about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:50:54 +0000
committerEric Wong <e@80x24.org>2019-12-27 20:00:37 +0000
commit1f53f1bf532a390f130c2029168cf90706595570 (patch)
tree6f856c8696b777d75528e0b8b768cf8975166073 /lib
parentdd5b6a982381327caabaa8942f6f82aa503a044e (diff)
downloadpublic-inbox-1f53f1bf532a390f130c2029168cf90706595570.tar.gz
Stash 5 local variables into the WWW $ctx hash table instead of
allocating several kilobytes for an anonymous sub.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/View.pm57
1 files changed, 32 insertions, 25 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 1ce6ba85..1e2d3b55 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -24,37 +24,44 @@ use constant INDENT => '  ';
 use constant TCHILD => '` ';
 sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
 
+sub msg_html_i {
+        my ($nr, $ctx) = @_;
+        my $more = $ctx->{more};
+        if ($nr == 1) {
+                # $more cannot be true w/o $smsg being defined:
+                my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
+                $ctx->{tip} .
+                        multipart_text_as_html($ctx->{mime}, $upfx, $ctx) .
+                        '</pre><hr>'
+        } elsif ($more && @$more) {
+                ++$ctx->{end_nr};
+                msg_html_more($ctx, $more, $nr);
+        } elsif ($nr == $ctx->{end_nr}) {
+                # fake an EOF if generating the footer fails;
+                # we want to at least show the message if something
+                # here crashes:
+                eval {
+                        my $hdr = delete($ctx->{mime})->header_obj;
+                        '<pre>' . html_footer($hdr, 1, $ctx) .
+                        '</pre>' . msg_reply($ctx, $hdr)
+                };
+        } else {
+                undef
+        }
+}
+
 # public functions: (unstable)
 
 sub msg_html {
         my ($ctx, $mime, $more, $smsg) = @_;
-        my $hdr = $mime->header_obj;
         my $ibx = $ctx->{-inbox};
         $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
-        my $tip = _msg_html_prepare($hdr, $ctx, $more, 0);
-        my $end = 2;
-        PublicInbox::WwwStream->response($ctx, 200, sub {
-                my ($nr, undef) = @_;
-                if ($nr == 1) {
-                        # $more cannot be true w/o $smsg being defined:
-                        my $upfx = $more ? '../'.mid_escape($smsg->mid).'/' : '';
-                        $tip . multipart_text_as_html($mime, $upfx, $ctx) .
-                                '</pre><hr>'
-                } elsif ($more && @$more) {
-                        ++$end;
-                        msg_html_more($ctx, $more, $nr);
-                } elsif ($nr == $end) {
-                        # fake an EOF if generating the footer fails;
-                        # we want to at least show the message if something
-                        # here crashes:
-                        eval {
-                                '<pre>' . html_footer($hdr, 1, $ctx) .
-                                '</pre>' . msg_reply($ctx, $hdr)
-                        };
-                } else {
-                        undef
-                }
-        });
+        $ctx->{tip} = _msg_html_prepare($mime->header_obj, $ctx, $more, 0);
+        $ctx->{more} = $more;
+        $ctx->{end_nr} = 2;
+        $ctx->{smsg} = $smsg;
+        $ctx->{mime} = $mime;
+        PublicInbox::WwwStream->response($ctx, 200, \&msg_html_i);
 }
 
 sub msg_page {