From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CE4371F48A for ; Sat, 15 Feb 2020 09:46:40 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/8] view: remove mhref arg from multipart_text_as_html Date: Sat, 15 Feb 2020 09:46:33 +0000 Message-Id: <20200215094640.19425-2-e@yhbt.net> In-Reply-To: <20200215094640.19425-1-e@yhbt.net> References: <20200215094640.19425-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 14 +++++++------- lib/PublicInbox/WwwAtomStream.pm | 3 ++- xt/perf-msgview.t | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index d097d8ab..dcaee1ae 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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}} .= '
'; } 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}} .= '
'; } @@ -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 { diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm index ea871fe5..658934a2 100644 --- a/lib/PublicInbox/WwwAtomStream.pm +++ b/lib/PublicInbox/WwwAtomStream.pm @@ -142,7 +142,8 @@ sub feed_entry { qq{} . qq(); $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 .= ''; } diff --git a/xt/perf-msgview.t b/xt/perf-msgview.t index f676ca93..3ea92ec6 100644 --- a/xt/perf-msgview.t +++ b/xt/perf-msgview.t @@ -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 = ''; } });