about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewDiff.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-09-10 08:17:08 +0000
committerEric Wong <e@80x24.org>2022-09-10 19:50:38 +0000
commite1190baa1463ee37e45b439a38f5e376ad39614b (patch)
treeffec0a7260da4ff47fca4cad9e575720479011ad /lib/PublicInbox/ViewDiff.pm
parent5ade6f79b3b7b2c3562cfa6fd7b8cf68223f0c0a (diff)
downloadpublic-inbox-e1190baa1463ee37e45b439a38f5e376ad39614b.tar.gz
Instead of appending to an ever-growing {obuf}, we'll reuse
the existing string (which already has pre-allocated memory).
Diffstat (limited to 'lib/PublicInbox/ViewDiff.pm')
-rw-r--r--lib/PublicInbox/ViewDiff.pm24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 349ffec8..b9194ed4 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -168,28 +168,26 @@ sub diff_header ($$$) {
 
 sub diff_before_or_after ($$) {
         my ($ctx, $x) = @_;
-        my $linkify = $ctx->{-linkify};
-        my $dst = $ctx->{obuf};
         if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n"
                         # diffstat lines:
                         ((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+)
                         (\x20[0-9]+\x20files?\x20)changed,([^\n]+\n)
                         (.*?)\z/msx) { # notes, commit message, etc
-                undef $$x;
                 my @x = ($5, $4, $3, $2, $1);
-                $$dst .= $linkify->to_html(pop @x); # uninteresting prefix
+                my $lnk = $ctx->{-linkify};
+                $$x = $lnk->to_html(pop @x); # uninteresting prefix
                 for my $l (split(/^/m, pop(@x))) { # per-file diffstat lines
                         $l =~ /^ (.+)( +\| .*\z)/s and
-                                anchor0($dst, $ctx, $1, $2) and next;
-                        $$dst .= $linkify->to_html($l);
+                                anchor0($x, $ctx, $1, $2) and next;
+                        $$x .= $lnk->to_html($l);
                 }
-                $$dst .= $x[2]; # $3 /^ \d+ files? /
+                $$x .= pop @x; # $3 /^ \d+ files? /
                 my $ch = $ctx->{changed_href} // '#related';
-                $$dst .= qq(<a href="$ch">changed</a>,);
-                $$dst .= ascii_html($x[1]); # $4: insertions/deletions
-                $$dst .= $linkify->to_html($x[0]); # notes, commit message, etc
+                $$x .= qq(<a href="$ch">changed</a>,);
+                $$x .= ascii_html(pop @x); # $4: insertions/deletions
+                $$x .= $lnk->to_html(pop @x); # notes, commit message, etc
         } else {
-                $$dst .= $linkify->to_html($$x);
+                $ctx->{-linkify}->to_html($$x);
         }
 }
 
@@ -247,9 +245,9 @@ sub flush_diff ($$) {
                                         $$dst .= $linkify->to_html($s);
                                 }
                         }
-                        diff_before_or_after($ctx, \$after) unless $dctx;
+                        $$dst .= diff_before_or_after($ctx, \$after) if !$dctx;
                 } else {
-                        diff_before_or_after($ctx, \$x);
+                        $$dst .= diff_before_or_after($ctx, \$x);
                 }
         }
 }