]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: eml_entry: reduce parameters
authorEric Wong <e@yhbt.net>
Sun, 5 Jul 2020 23:27:50 +0000 (23:27 +0000)
committerEric Wong <e@yhbt.net>
Mon, 6 Jul 2020 20:01:15 +0000 (20:01 +0000)
We can save stack space and simplify subroutine calls, here.

Documentation/mknews.perl
lib/PublicInbox/Feed.pm
lib/PublicInbox/SearchView.pm
lib/PublicInbox/View.pm

index 51d54b7167c19c8517b3e21787515f839b6e960d..4a5d0e563bc425a9539349c761059cbc12aa48f9 100755 (executable)
@@ -103,9 +103,9 @@ sub mime2txt {
 
 sub mime2html {
        my ($out, $eml, $ctx) = @_;
-       my $smsg = bless {}, 'PublicInbox::Smsg';
+       my $smsg = $ctx->{smsg} = bless {}, 'PublicInbox::Smsg';
        $smsg->populate($eml);
-       print $out PublicInbox::View::eml_entry($ctx, $smsg, $eml, 1) or die;
+       print $out PublicInbox::View::eml_entry($ctx, $eml, 1) or die;
 }
 
 sub html_start {
index 279106d2803f32d93b0ee558fb3573e3e266f362..476d946f515d2882e881d61ab3c0117c38042721 100644 (file)
@@ -51,7 +51,7 @@ sub new_html_i {
        my ($ctx, $eml) = @_;
        $ctx->zmore($ctx->html_top) if exists $ctx->{-html_tip};
 
-       $eml and return PublicInbox::View::eml_entry($ctx, $ctx->{smsg}, $eml,
+       $eml and return PublicInbox::View::eml_entry($ctx, $eml,
                                                scalar @{$ctx->{msgs}});
        my $smsg = shift @{$ctx->{msgs}} or
                $ctx->zmore(PublicInbox::View::pagination_footer(
index 921992a5d0c001bfe6faf2935292ad232ea30fcd..623b16fb22cd0d6282d01d001a16dd367531080e 100644 (file)
@@ -294,7 +294,7 @@ sub mset_thread {
 sub mset_thread_i {
        my ($ctx, $eml) = @_;
        $ctx->zmore($ctx->html_top) if exists $ctx->{-html_tip};
-       $eml and return PublicInbox::View::eml_entry($ctx, $ctx->{smsg}, $eml,
+       $eml and return PublicInbox::View::eml_entry($ctx, $eml,
                                                scalar @{$ctx->{msgs}});
        my $smsg = shift @{$ctx->{msgs}} or
                $ctx->zmore(${delete($ctx->{skel})});
index 16a0fcdfbe3406c4f110b6a733b4b5078e56dce1..65695392817990f0748d8a560f567776d3b42a5f 100644 (file)
@@ -181,7 +181,8 @@ sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
 # Displays the text of of the message for /$INBOX/$MSGID/[Tt]/ endpoint
 # this is already inside a <pre>
 sub eml_entry {
-       my ($ctx, $smsg, $eml, $more) = @_;
+       my ($ctx, $eml, $more) = @_;
+       my $smsg = delete $ctx->{smsg};
        my $subj = delete $smsg->{subject};
        my $mid_raw = $smsg->{mid};
        my $id = id_compress($mid_raw, 1);
@@ -370,9 +371,9 @@ sub pre_thread  { # walk_thread callback
 }
 
 sub thread_eml_entry {
-       my ($ctx, $level, $smsg, $eml) = @_;
-       my ($beg, $end) = thread_adj_level($ctx, $level);
-       $beg . '<pre>' . eml_entry($ctx, $smsg, $eml, 0) . '</pre>' . $end;
+       my ($ctx, $eml) = @_;
+       my ($beg, $end) = thread_adj_level($ctx, $ctx->{level});
+       $beg . '<pre>' . eml_entry($ctx, $eml, 0) . '</pre>' . $end;
 }
 
 sub next_in_queue ($$) {
@@ -390,12 +391,12 @@ sub stream_thread_i { # PublicInbox::WwwStream::getline callback
        my ($ctx, $eml) = @_;
 
        if ($eml) {
-               my ($level, $smsg) = delete @$ctx{qw(level smsg)};
                if ($ctx->{nr} == 1) {
-                       $ctx->{-title_html} = ascii_html($smsg->{subject});
+                       $ctx->{-title_html} =
+                                       ascii_html($ctx->{smsg}->{subject});
                        $ctx->zmore($ctx->html_top);
                }
-               return thread_eml_entry($ctx, $level, $smsg, $eml);
+               goto &thread_eml_entry; # tail recursion
        }
        return unless exists($ctx->{skel});
        my $ghost_ok = $ctx->{nr}++;
@@ -470,7 +471,7 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback
                        $ctx->{-title_html} = ascii_html($smsg->{subject});
                        $ctx->zmore($ctx->html_top);
                }
-               return eml_entry($ctx, $smsg, $eml, scalar @{$ctx->{msgs}});
+               return eml_entry($ctx, $eml, scalar @{$ctx->{msgs}});
        } else {
                while (my $smsg = shift @{$ctx->{msgs}}) {
                        return $smsg if exists($smsg->{blob});