diff options
author | Eric Wong <e@80x24.org> | 2019-12-25 07:50:37 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-12-26 10:48:19 +0000 |
commit | 2b8dff053f61a15cd2987fdab8e60c2e4b6aa819 (patch) | |
tree | ab3153635886168fe1b75ad871364c053933ab3e /lib/PublicInbox/Qspawn.pm | |
parent | bfa40d0c4a970e5af0eae0441920a491c4f6fa1d (diff) | |
download | public-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/Qspawn.pm')
-rw-r--r-- | lib/PublicInbox/Qspawn.pm | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index c2856609..22603ca7 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -155,13 +155,13 @@ sub start { # $env is the PSGI env. As with ``/qx; only use this when output is small # and safe to slurp. sub psgi_qx { - my ($self, $env, $limiter, $qx_cb) = @_; + my ($self, $env, $limiter, $qx_cb, $cb_arg) = @_; my $scalar = ''; open(my $qx, '+>', \$scalar) or die; # PerlIO::scalar my $end = sub { my $err = $_[0]; # $! log_err($env, "psgi_qx: $err") if defined($err); - finish($self, $env, sub { $qx_cb->(\$scalar) }); + finish($self, $env, sub { $qx_cb->(\$scalar, $cb_arg) }); $qx = undef; }; my $rpipe; # comes from popen_rd |