From e1190baa1463ee37e45b439a38f5e376ad39614b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Sep 2022 08:17:08 +0000 Subject: viewdiff: reuse existing string in diff_before_or_after Instead of appending to an ever-growing {obuf}, we'll reuse the existing string (which already has pre-allocated memory). --- lib/PublicInbox/ViewDiff.pm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'lib/PublicInbox/ViewDiff.pm') 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(changed,); - $$dst .= ascii_html($x[1]); # $4: insertions/deletions - $$dst .= $linkify->to_html($x[0]); # notes, commit message, etc + $$x .= qq(changed,); + $$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); } } } -- cgit v1.2.3-24-ge0c7