From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 383FA1FC72 for ; Wed, 25 Dec 2019 07:51:10 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 28/30] viewvcs: avoid anonymous sub for HTML response Date: Wed, 25 Dec 2019 07:51:02 +0000 Message-Id: <20191225075104.22184-29-e@80x24.org> In-Reply-To: <20191225075104.22184-1-e@80x24.org> References: <20191225075104.22184-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No need to create a new sub for every HTML page we render with our VCS viewer. --- lib/PublicInbox/ViewVCS.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 7618b198..a6dbb9a9 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -31,14 +31,17 @@ my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' ); our $MAX_SIZE = 1024 * 1024; # TODO: configurable my $BIN_DETECT = 8000; # same as git +sub html_i { # WwwStream::getline callback + my ($nr, $ctx) = @_; + $nr == 1 ? ${delete $ctx->{rv}} : undef; +} + sub html_page ($$$) { my ($ctx, $code, $strref) = @_; my $wcb = delete $ctx->{-wcb}; $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/" - my $res = PublicInbox::WwwStream->response($ctx, $code, sub { - my ($nr, undef) = @_; - $nr == 1 ? $$strref : undef; - }); + $ctx->{rv} = $strref; + my $res = PublicInbox::WwwStream->response($ctx, $code, \&html_i); $wcb ? $wcb->($res) : $res; }