]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: allow html_oneshot to take an array arg
authorEric Wong <e@80x24.org>
Mon, 29 Aug 2022 09:26:33 +0000 (09:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 29 Aug 2022 19:05:44 +0000 (19:05 +0000)
Another step towards making our internal APIs more writev-like
and reducing the copies needed for `join' or `.=' concatenation.

lib/PublicInbox/View.pm
lib/PublicInbox/ViewVCS.pm
lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwAltId.pm
lib/PublicInbox/WwwStream.pm
lib/PublicInbox/WwwText.pm

index 158feb6ab3d5a6a933e04c41bf44dd1dd9a82aaf..5fbdd1fa88cbd9aca73deca28c3b0cb5a9f75552 100644 (file)
@@ -64,7 +64,7 @@ sub no_over_html ($) {
        }
        delete $ctx->{obuf};
        eval { $$obuf .= html_footer($ctx, $eml) };
-       html_oneshot($ctx, 200, $obuf);
+       html_oneshot($ctx, 200, $$obuf);
 }
 
 # public functions: (unstable)
@@ -1222,7 +1222,7 @@ sub pagination_footer ($$) {
                $next = $next ? "$next | " : '             | ';
                $prev .= qq[ | <a\nhref="$latest">latest</a>];
        }
-       ($next || $prev) ? \"<hr><pre>page: $next$prev</pre>" : \'';
+       ($next || $prev) ? "<hr><pre>page: $next$prev</pre>" : '';
 }
 
 sub paginate_recent ($$) {
index b04a5672028e226ad66a2c50bd89687092b27387..23524ac00b7e1a937b8924ba868adaa83f0c58d1 100644 (file)
@@ -36,11 +36,11 @@ my $BIN_DETECT = 8000; # same as git
 my $SHOW_FMT = '--pretty=format:'.join('%n', '%P', '%p', '%H', '%T', '%s',
        '%an <%ae>  %ai', '%cn <%ce>  %ci', '%b%x00');
 
-sub html_page ($$$) {
-       my ($ctx, $code, $str) = @_;
+sub html_page ($$;@) {
+       my ($ctx, $code) = @_[0, 1];
        my $wcb = delete $ctx->{-wcb};
        $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
-       my $res = html_oneshot($ctx, $code, \$str);
+       my $res = html_oneshot($ctx, $code, @_[2..$#_]);
        $wcb ? $wcb->($res) : $res;
 }
 
index 77f463d37ee5f7a1b0e774f2593b41f91524583c..1df5572db61c8a82b217090cbc8e9c27efd9f841 100644 (file)
@@ -320,7 +320,7 @@ sub get_altid_dump {
 sub need {
        my ($ctx, $extra) = @_;
        require PublicInbox::WwwStream;
-       PublicInbox::WwwStream::html_oneshot($ctx, 501, \<<EOF);
+       PublicInbox::WwwStream::html_oneshot($ctx, 501, <<EOF);
 <pre>$extra is not available for this public-inbox
 <a\nhref="../">Return to index</a></pre>
 EOF
index e107dfe06eafb3cbcc3183b73399210c36ea4781..470561608f5df47b746cd5bab5680d23b47f3c33 100644 (file)
@@ -33,14 +33,14 @@ sub sqldump ($$) {
        my $altid_map = $ibx->altid_map;
        my $fn = $altid_map->{$altid_pfx};
        unless (defined $fn) {
-               return html_oneshot($ctx, 404, \<<EOF);
+               return html_oneshot($ctx, 404, <<EOF);
 <pre>`$altid_pfx' is not a valid altid for this inbox</pre>
 EOF
        }
 
        if ($env->{REQUEST_METHOD} ne 'POST') {
                my $url = $ibx->base_url($ctx->{env}) . "$altid_pfx.sql.gz";
-               return html_oneshot($ctx, 405, \<<EOF);
+               return html_oneshot($ctx, 405, <<EOF);
 <pre>A POST request is required to retrieve $altid_pfx.sql.gz
 
        curl -d '' -O $url
@@ -54,7 +54,7 @@ or
 EOF
        }
 
-       $sqlite3 //= which('sqlite3') // return html_oneshot($ctx, 501, \<<EOF);
+       $sqlite3 //= which('sqlite3') // return html_oneshot($ctx, 501, <<EOF);
 <pre>sqlite3 not available
 
 The administrator needs to install the sqlite3(1) binary
index ab006c40509dc336a4c6bfa2a12fa5136a0131fd..f2777fdc64f8a33fdaa945db9f7eded819514dc2 100644 (file)
@@ -164,8 +164,8 @@ sub getline {
        $ctx->zflush(_html_end($ctx));
 }
 
-sub html_oneshot ($$;$) {
-       my ($ctx, $code, $sref) = @_;
+sub html_oneshot ($$;@) {
+       my ($ctx, $code) = @_[0, 1];
        my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
                'Content-Length' => undef ];
        bless $ctx, __PACKAGE__;
@@ -174,8 +174,7 @@ sub html_oneshot ($$;$) {
                $ctx->zmore(html_top($ctx));
                $ctx->{base_url} = base_url($ctx);
        };
-       $ctx->zmore($$sref) if $sref;
-       my $bdy = $ctx->zflush(_html_end($ctx));
+       my $bdy = $ctx->zflush(@_[2..$#_], _html_end($ctx));
        $res_hdr->[3] = length($bdy);
        [ $code, $res_hdr, [ $bdy ] ]
 }
index c6957e813229c01c5c217f5a0c65bb0025afe8f0..3f840c447fdf37c3dc3cec8eae518840524d1a76 100644 (file)
@@ -70,7 +70,7 @@ sub get_text {
        $txt =~ s!\bPOP3\b!<a\nid=pop3>POP3</a>!;
        $txt =~ s!\b(Newsgroups?)\b!<a\nid=nntp>$1</a>!;
        $txt =~ s!\bIMAP\b!<a\nid=imap>IMAP</a>!;
-       PublicInbox::WwwStream::html_oneshot($ctx, $code, \$txt);
+       PublicInbox::WwwStream::html_oneshot($ctx, $code, $txt);
 }
 
 sub _srch_prefix ($$) {