unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 04/18] www: allow html_oneshot to take an array arg
Date: Mon, 29 Aug 2022 09:26:33 +0000	[thread overview]
Message-ID: <20220829092647.1512215-5-e@80x24.org> (raw)
In-Reply-To: <20220829092647.1512215-1-e@80x24.org>

Another step towards making our internal APIs more writev-like
and reducing the copies needed for `join' or `.=' concatenation.
---
 lib/PublicInbox/View.pm      | 4 ++--
 lib/PublicInbox/ViewVCS.pm   | 6 +++---
 lib/PublicInbox/WWW.pm       | 2 +-
 lib/PublicInbox/WwwAltId.pm  | 6 +++---
 lib/PublicInbox/WwwStream.pm | 7 +++----
 lib/PublicInbox/WwwText.pm   | 2 +-
 6 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 158feb6a..5fbdd1fa 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -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 ($$) {
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index b04a5672..23524ac0 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -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;
 }
 
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 77f463d3..1df5572d 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -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
diff --git a/lib/PublicInbox/WwwAltId.pm b/lib/PublicInbox/WwwAltId.pm
index e107dfe0..47056160 100644
--- a/lib/PublicInbox/WwwAltId.pm
+++ b/lib/PublicInbox/WwwAltId.pm
@@ -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
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index ab006c40..f2777fdc 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -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 ] ]
 }
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index c6957e81..3f840c44 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -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 ($$) {

  parent reply	other threads:[~2022-08-29  9:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29  9:26 [PATCH 00/18] WWW: patch, tree, git glossary Eric Wong
2022-08-29  9:26 ` [PATCH 01/18] solver: create tmpdir lazily Eric Wong
2022-08-29  9:26 ` [PATCH 02/18] viewvcs: share File::Temp::Dir with solver Eric Wong
2022-08-29  9:26 ` [PATCH 03/18] viewvcs: delay stringification of solver debug log Eric Wong
2022-08-29  9:26 ` Eric Wong [this message]
2022-08-29  9:26 ` [PATCH 05/18] viewvcs: use array for highlighted blob display Eric Wong
2022-08-29  9:26 ` [PATCH 06/18] viewvcs: add patch download link for single-parent commits Eric Wong
2022-08-29  9:26 ` [PATCH 07/18] viewvcs: author date links to contemporary messages Eric Wong
2022-08-29  9:26 ` [PATCH 08/18] view: speed up /$INBOX/ landing page by 0.5-1.0% Eric Wong
2022-08-29  9:26 ` [PATCH 09/18] treewide: ditch inbox->recent method Eric Wong
2022-08-29  9:26 ` [PATCH 10/18] view: /$INBOX/: show "messages from $old to $new" Eric Wong
2022-08-29  9:26 ` [PATCH 11/18] view: cleanups and reuse for {obuf} preparation Eric Wong
2022-08-29  9:26 ` [PATCH 12/18] www: atom: fix "changed" href to nowhere Eric Wong
2022-08-29  9:26 ` [PATCH 13/18] www: provide text/help/#search anchor Eric Wong
2022-08-29  9:26 ` [PATCH 14/18] solver: early make hints detection more robust Eric Wong
2022-08-29  9:26 ` [PATCH 15/18] viewvcs: add tree view Eric Wong
2022-08-29  9:26 ` [PATCH 16/18] viewvcs: reduce hash assignments for commit info Eric Wong
2022-08-29  9:26 ` [PATCH 17/18] viewvcs: add glossary for commit Eric Wong
2022-08-29  9:57   ` [19/18 PATCH] viewvcs: fixup commit glossary stuff Eric Wong
2022-08-29  9:26 ` [PATCH 18/18] viewvcs: show "blob $OID" rather than "$OID blob" Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220829092647.1512215-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).