]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: /$INBOX/$MSGID/t/: avoid extra hash lookup in eml case
[public-inbox.git] / lib / PublicInbox / View.pm
index 16a0fcdfbe3406c4f110b6a733b4b5078e56dce1..138e0c3a217d6173de7049c577fcc0ea72769594 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 ($$) {
@@ -388,15 +389,7 @@ sub next_in_queue ($$) {
 
 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->zmore($ctx->html_top);
-               }
-               return thread_eml_entry($ctx, $level, $smsg, $eml);
-       }
+       goto &thread_eml_entry if $eml; # tail recursion
        return unless exists($ctx->{skel});
        my $ghost_ok = $ctx->{nr}++;
        while (1) {
@@ -404,6 +397,11 @@ sub stream_thread_i { # PublicInbox::WwwStream::getline callback
                if ($smsg) {
                        if (exists $smsg->{blob}) { # next message for cat-file
                                $ctx->{level} = $lvl;
+                               if (!$ghost_ok) { # first non-ghost
+                                       $ctx->{-title_html} =
+                                               ascii_html($smsg->{subject});
+                                       $ctx->zmore($ctx->html_top);
+                               }
                                return $smsg;
                        }
                        # buffer the ghost entry and loop
@@ -470,7 +468,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});