about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewVCS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:50:37 +0000
committerEric Wong <e@80x24.org>2019-12-26 10:48:19 +0000
commit2b8dff053f61a15cd2987fdab8e60c2e4b6aa819 (patch)
treeab3153635886168fe1b75ad871364c053933ab3e /lib/PublicInbox/ViewVCS.pm
parentbfa40d0c4a970e5af0eae0441920a491c4f6fa1d (diff)
downloadpublic-inbox-2b8dff053f61a15cd2987fdab8e60c2e4b6aa819.tar.gz
By passing a user-supplied arg to $qx_cb, we can eliminate the
callers' need to capture on-stack variables with a closure.
This saves several kilobytes of memory allocation at the expense
of some extra hash table lookups in user-supplied callbacks.  It
also reduces the risk of memory leaks by eliminating a common
source of circular references.
Diffstat (limited to 'lib/PublicInbox/ViewVCS.pm')
-rw-r--r--lib/PublicInbox/ViewVCS.pm33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 842c873c..886e10cb 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -73,6 +73,22 @@ sub stream_large_blob ($$$$) {
         });
 }
 
+sub show_other_result ($$) {
+        my ($bref, $ctx) = @_;
+        my ($qsp, $logref) = delete @$ctx{qw(-qsp -logref)};
+        if (my $err = $qsp->{err}) {
+                utf8::decode($$err);
+                $$logref .= "git show error: $err";
+                return html_page($ctx, 500, $logref);
+        }
+        my $l = PublicInbox::Linkify->new;
+        utf8::decode($$bref);
+        $l->linkify_1($$bref);
+        $$bref = '<pre>'. $l->linkify_2(ascii_html($$bref));
+        $$bref .= '</pre><hr>' . $$logref;
+        html_page($ctx, 200, $bref);
+}
+
 sub show_other ($$$$) {
         my ($ctx, $res, $logref, $fn) = @_;
         my ($git, $oid, $type, $size) = @$res;
@@ -84,20 +100,9 @@ sub show_other ($$$$) {
                 qw(show --encoding=UTF-8 --no-color --no-abbrev), $oid ];
         my $qsp = PublicInbox::Qspawn->new($cmd);
         my $env = $ctx->{env};
-        $qsp->psgi_qx($env, undef, sub {
-                my ($bref) = @_;
-                if (my $err = $qsp->{err}) {
-                        utf8::decode($$err);
-                        $$logref .= "git show error: $err";
-                        return html_page($ctx, 500, $logref);
-                }
-                my $l = PublicInbox::Linkify->new;
-                utf8::decode($$bref);
-                $l->linkify_1($$bref);
-                $$bref = '<pre>'. $l->linkify_2(ascii_html($$bref));
-                $$bref .= '</pre><hr>' . $$logref;
-                html_page($ctx, 200, $bref);
-        });
+        $ctx->{-qsp} = $qsp;
+        $ctx->{-logref} = $logref;
+        $qsp->psgi_qx($env, undef, \&show_other_result, $ctx);
 }
 
 sub solve_result {