]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: remove mhref arg from multipart_text_as_html
authorEric Wong <e@yhbt.net>
Sat, 15 Feb 2020 09:46:33 +0000 (09:46 +0000)
committerEric Wong <e@yhbt.net>
Sun, 16 Feb 2020 00:06:21 +0000 (00:06 +0000)
No point in passing something on stack only to stash it
into the $ctx which holds most other parameters used for
rendering the HTML.

lib/PublicInbox/View.pm
lib/PublicInbox/WwwAtomStream.pm
xt/perf-msgview.t

index d097d8ab4d86267fc13c52d75fd272b27fcbc289..dcaee1aeaeca6c8fdb8c6c57e9011693c04421f8 100644 (file)
@@ -29,8 +29,9 @@ sub msg_page_i {
        my $more = $ctx->{more};
        if ($nr == 1) {
                # $more cannot be true w/o $smsg being defined:
-               my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
-               multipart_text_as_html(delete $ctx->{mime}, $upfx, $ctx);
+               $ctx->{mhref} = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/'
+                                     : '';
+               multipart_text_as_html(delete $ctx->{mime}, $ctx);
                ${delete $ctx->{obuf}} .= '</pre><hr>';
        } elsif ($more) {
                ++$ctx->{end_nr};
@@ -83,10 +84,10 @@ sub msg_page_more {
        my $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
        $ctx->{more} = $next ? [ $id, $prev, $next ] : undef;
        return '' unless $smsg;
-       my $upfx = '../' . mid_escape($smsg->mid) . '/';
+       $ctx->{mhref} = '../' . mid_escape($smsg->mid) . '/';
        my $mime = delete $smsg->{mime};
        _msg_page_prepare_obuf($mime->header_obj, $ctx, $nr);
-       multipart_text_as_html($mime, $upfx, $ctx);
+       multipart_text_as_html($mime, $ctx);
        ${delete $ctx->{obuf}} .= '</pre><hr>';
 }
 
@@ -486,11 +487,10 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback
 }
 
 sub multipart_text_as_html {
-       my (undef, $mhref, $ctx) = @_; # $mime = $_[0]
-       $ctx->{mhref} = $mhref;
+       # ($mime, $ctx) = @_; # msg_iter will do "$_[0] = undef"
 
        # scan through all parts, looking for displayable text
-       msg_iter($_[0], \&add_text_body, $ctx, 1);
+       msg_iter($_[0], \&add_text_body, $_[1], 1);
 }
 
 sub flush_quote {
index ea871fe54a2ee4b4362a7196b1ae9d209e1f590e..658934a27d572e027e3c70d1b23f34e3071c646b 100644 (file)
@@ -142,7 +142,8 @@ sub feed_entry {
                qq{<div\nxmlns="http://www.w3.org/1999/xhtml">} .
                qq(<pre\nstyle="white-space:pre-wrap">);
        $ctx->{obuf} = \$s;
-       PublicInbox::View::multipart_text_as_html($mime, $href, $ctx);
+       $ctx->{mhref} = $href;
+       PublicInbox::View::multipart_text_as_html($mime, $ctx);
        delete $ctx->{obuf};
        $s .= '</pre></div></content></entry>';
 }
index f676ca936decc9459db31977b46f46108d29c347..3ea92ec67f063879dc58871fe9de27c16a90c5a6 100644 (file)
@@ -37,13 +37,14 @@ my $n = 0;
 my $t = timeit(1, sub {
        my $obuf = '';
        $ctx->{obuf} = \$obuf;
+       $ctx->{mhref} = '../';
        while (<$fh>) {
                ($cmt, $type) = split / /;
                next if $type ne 'blob';
                ++$n;
                $str = $git->cat_file($cmt);
                $mime = PublicInbox::MIME->new($str);
-               PublicInbox::View::multipart_text_as_html($mime, '../', $ctx);
+               PublicInbox::View::multipart_text_as_html($mime, $ctx);
                $obuf = '';
        }
 });