about summary refs log tree commit homepage
path: root/lib/PublicInbox/View.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-01-25 04:45:10 +0000
committerEric Wong <e@yhbt.net>2020-01-27 02:59:09 +0000
commitddec19694cbf0e1d94fb56c0fc4bd90eae540884 (patch)
tree67b174dd71519fd5b14f57f2740e41fd3645ffe6 /lib/PublicInbox/View.pm
parent19671d5736639c9f5d063a87a075fd309e41d203 (diff)
downloadpublic-inbox-ddec19694cbf0e1d94fb56c0fc4bd90eae540884.tar.gz
Instead of going line-by-line, use split() with a giant regexp
to capture groups of contiguous lines.  This offloads state
management to the regexp itself and makes it FAR easier to
keep track of <span> and </span> pairings.

Performance seems roughly on par after this change for the
meta@public-inbox archives.  It seems a tiny bit faster for
git@vger with xt/perf-msgview.t, likely due to the longer
messages and larger contiguous groups of lines having the same
prefix (or no prefix at all) and drastically reduces the number
of subroutine calls and Perl ops executed.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r--lib/PublicInbox/View.pm8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index e604aee0..ff36777c 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -562,7 +562,7 @@ sub add_text_body { # callback for msg_iter
                 $idx[0] = $upfx . $idx[0] if $upfx ne '';
                 $ctx->{-apfx} = join('/', @idx);
                 $ctx->{-anchors} = {}; # attr => filename
-                $ctx->{-diff} = $diff = [];
+                $diff = 1;
                 delete $ctx->{-long_path};
                 my $spfx;
                 if ($ibx->{-repo_objs}) {
@@ -595,14 +595,12 @@ sub add_text_body { # callback for msg_iter
                 attach_link($ctx, $ct, $p, $fn, $err);
                 $$rv .= "\n";
         }
-        my $l = PublicInbox::Linkify->new;
+        my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new;
         foreach my $cur (@sections) {
                 if ($cur =~ /\A>/) {
                         flush_quote($rv, $l, \$cur);
                 } elsif ($diff) {
-                        @$diff = split(/^/m, $cur);
-                        $cur = undef;
-                        flush_diff($rv, $ctx, $l);
+                        flush_diff($rv, $ctx, \$cur);
                 } else {
                         # regular lines, OK
                         $$rv .= $l->to_html($cur);