* [PATCH 11/18] view: cleanups and reuse for {obuf} preparation
2022-08-29 9:26 7% [PATCH 00/18] WWW: patch, tree, git glossary Eric Wong
@ 2022-08-29 9:26 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-08-29 9:26 UTC (permalink / raw)
To: meta
{obuf} will eventually go away and we'll write directly to
{zbuf}, but as an intermediate step we'll make some changes
to rely less on return values.
While we're in the area, reuse Linkify objects in more places
where possible to save some allocations.
---
lib/PublicInbox/View.pm | 49 ++++++++++++++++++++---------------------
t/plack.t | 2 +-
2 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 11ed2d76..354cdd93 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -38,7 +38,7 @@ sub msg_page_i {
: $ctx->gone('over');
$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
"../${\mid_href($smsg->{mid})}/" : '';
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
+ my $obuf = _msg_page_prepare_obuf($eml, $ctx);
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
@@ -58,7 +58,7 @@ sub no_over_html ($) {
my $eml = PublicInbox::Eml->new($bref);
$ctx->{mhref} = '';
PublicInbox::WwwStream::init($ctx);
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
+ my $obuf = _msg_page_prepare_obuf($eml, $ctx);
if (length($$obuf)) {
multipart_text_as_html($eml, $ctx);
$$obuf .= '</pre><hr>';
@@ -661,9 +661,9 @@ sub add_text_body { # callback for each_part
sub _msg_page_prepare_obuf {
my ($eml, $ctx) = @_;
- my $over = $ctx->{ibx}->over;
+ my $have_over = !!$ctx->{ibx}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
- my $rv = '';
+ $ctx->{obuf} = \(my $rv = '');
my $mids = mids_for_index($eml);
my $nr = $ctx->{nr}++;
if ($nr) { # unlikely
@@ -672,14 +672,13 @@ sub _msg_page_prepare_obuf {
return \$rv;
}
$rv .=
-"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
- $rv .= '<pre>';
+"<pre>WARNING: multiple messages have this Message-ID\n</pre><pre>";
} else {
$ctx->{first_hdr} = $eml->header_obj;
$ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
$rv .= "<pre\nid=b>"; # anchor for body start
}
- $ctx->{-upfx} = '../' if $over;
+ $ctx->{-upfx} = '../' if $have_over;
my @title; # (Subject[0], From[0])
for my $v ($eml->header('From')) {
my @n = PublicInbox::Address::names($v);
@@ -704,7 +703,7 @@ sub _msg_page_prepare_obuf {
my $v = ascii_html(shift @subj);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
$rv .= 'Subject: ';
- $rv .= $over ? qq(<a\nhref="#r"\nid=t>$v</a>\n) : "$v\n";
+ $rv .= $have_over ? qq(<a\nhref="#r"\nid=t>$v</a>\n) : "$v\n";
$title[0] = $v;
for $v (@subj) { # multi-Subject message :<
$v = ascii_html($v);
@@ -712,7 +711,7 @@ sub _msg_page_prepare_obuf {
$rv .= "Subject: $v\n";
}
} else { # dummy anchor for thread skeleton at bottom of page
- $rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
+ $rv .= qq(<a\nhref="#r"\nid=t></a>) if $have_over;
$title[0] = '(no subject)';
}
for my $v ($eml->header('Date')) {
@@ -724,22 +723,22 @@ sub _msg_page_prepare_obuf {
$ctx->{-title_html} = join(' - ', @title);
$rv = $ctx->html_top . $rv;
}
+
+ $ctx->{-linkify} //= PublicInbox::Linkify->new;
if (scalar(@$mids) == 1) { # common case
my $mhtml = ascii_html($mids->[0]);
- $rv .= "Message-ID: <$mhtml> ";
- $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
+ $rv .= qq[Message-ID: <$mhtml> (<a href="raw">raw</a>)\n];
} else {
# X-Alt-Message-ID can happen if a message is injected from
# public-inbox-nntpd because of multiple Message-ID headers.
- my $lnk = PublicInbox::Linkify->new;
my $s = '';
for my $h (qw(Message-ID X-Alt-Message-ID)) {
$s .= "$h: $_\n" for ($eml->header_raw($h));
}
- $lnk->linkify_mids('..', \$s, 1);
+ $ctx->{-linkify}->linkify_mids('..', \$s, 1);
$rv .= $s;
}
- $rv .= _parent_headers($eml, $over);
+ _parent_headers($ctx, $eml);
$rv .= "\n";
\$rv;
}
@@ -792,35 +791,35 @@ sub thread_skel ($$$) {
}
sub _parent_headers {
- my ($hdr, $over) = @_;
- my $rv = '';
+ my ($ctx, $hdr) = @_;
my @irt = $hdr->header_raw('In-Reply-To');
my $refs;
if (@irt) {
- my $lnk = PublicInbox::Linkify->new;
- $rv .= "In-Reply-To: $_\n" for @irt;
- $lnk->linkify_mids('..', \$rv);
+ my $s = '';
+ $s .= "In-Reply-To: $_\n" for @irt;
+ $ctx->{-linkify}->linkify_mids('..', \$s);
+ ${$ctx->{obuf}} .= $s;
} else {
$refs = references($hdr);
my $irt = pop @$refs;
if (defined $irt) {
my $html = ascii_html($irt);
my $href = mid_href($irt);
- $rv .= "In-Reply-To: <";
- $rv .= "<a\nhref=\"../$href/\">$html</a>>\n";
+ ${$ctx->{obuf}} .= <<EOM;
+In-Reply-To: <<a\nhref="../$href/">$html</a>>
+EOM
}
}
# do not display References: if search is present,
# we show the thread skeleton at the bottom, instead.
- return $rv if $over;
+ return if $ctx->{ibx}->over;
$refs //= references($hdr);
if (@$refs) {
- @$refs = map { linkify_ref_no_over($_) } @$refs;
- $rv .= 'References: '. join("\n\t", @$refs) . "\n";
+ $_ = linkify_ref_no_over($_) for @$refs;
+ ${$ctx->{obuf}} .= 'References: '. join("\n\t", @$refs) . "\n";
}
- $rv;
}
# returns a string buffer
diff --git a/t/plack.t b/t/plack.t
index 20f5d8d5..32209c7d 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -155,7 +155,7 @@ my $c1 = sub {
is(200, $res->code, "success for $path");
my $html = $res->content;
like($html, qr!<title>hihi - Me</title>!, 'HTML returned');
- like($html, qr!<a\nhref="raw"!s, 'raw link present');
+ like($html, qr!<a\nhref=raw!s, 'raw link present');
like($html, qr!> quoted text!s, 'quoted text inline');
$path .= 'f/';
^ permalink raw reply related [relevance 6%]
* [PATCH 00/18] WWW: patch, tree, git glossary
@ 2022-08-29 9:26 7% Eric Wong
2022-08-29 9:26 6% ` [PATCH 11/18] view: cleanups and reuse for {obuf} preparation Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-08-29 9:26 UTC (permalink / raw)
To: meta
Raw format-patch and tree HTML output now supported for git
output. I suppose tags can be displayed, too, at some point...
One thing I'm not 100% sure about is adding a git-related
glossary for stuff like trees, commits, etc... It seems
to bloat the page a bit, but it could be useful in slowly
teaching basic git data concepts to beginners.
I suspect folks who have trouble learning git too focused on the
commands rather than the data concepts. (IMHO, the same goes
for learning projects based on studying code vs studying
(DB schemas || struct layouts)).
I snuck one speedup in there, hopefully more to come...
Eric Wong (18):
solver: create tmpdir lazily
viewvcs: share File::Temp::Dir with solver
viewvcs: delay stringification of solver debug log
www: allow html_oneshot to take an array arg
viewvcs: use array for highlighted blob display
viewvcs: add patch download link for single-parent commits
viewvcs: author date links to contemporary messages
view: speed up /$INBOX/ landing page by 0.5-1.0%
treewide: ditch inbox->recent method
view: /$INBOX/: show "messages from $old to $new"
view: cleanups and reuse for {obuf} preparation
www: atom: fix "changed" href to nowhere
www: provide text/help/#search anchor
solver: early make hints detection more robust
viewvcs: add tree view
viewvcs: reduce hash assignments for commit info
viewvcs: add glossary for commit
viewvcs: show "blob $OID" rather than "$OID blob"
lib/PublicInbox/ExtSearch.pm | 1 -
lib/PublicInbox/Inbox.pm | 5 -
lib/PublicInbox/LeiSavedSearch.pm | 1 -
lib/PublicInbox/LeiXSearch.pm | 7 -
lib/PublicInbox/SolverGit.pm | 22 +-
lib/PublicInbox/View.pm | 101 ++++-----
lib/PublicInbox/ViewDiff.pm | 18 +-
lib/PublicInbox/ViewVCS.pm | 341 ++++++++++++++++++++----------
lib/PublicInbox/WWW.pm | 2 +-
lib/PublicInbox/WwwAltId.pm | 6 +-
lib/PublicInbox/WwwAtomStream.pm | 1 +
lib/PublicInbox/WwwStream.pm | 7 +-
lib/PublicInbox/WwwText.pm | 3 +-
t/convert-compact.t | 2 +-
t/indexlevels-mirror.t | 10 +-
t/lei_xsearch.t | 2 +-
t/plack.t | 2 +-
t/replace.t | 4 +-
t/solver_git.t | 3 +-
t/v1-add-remove-add.t | 2 +-
t/v2-add-remove-add.t | 2 +-
21 files changed, 333 insertions(+), 209 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-08-29 9:26 7% [PATCH 00/18] WWW: patch, tree, git glossary Eric Wong
2022-08-29 9:26 6% ` [PATCH 11/18] view: cleanups and reuse for {obuf} preparation Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).