diff options
author | Eric Wong <e@80x24.org> | 2022-09-26 10:17:12 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-09-26 19:22:02 +0000 |
commit | 06600f6ea9258425f4f7ff7a7b1f3d028d11b638 (patch) | |
tree | 6a7dcad9b34890b5df1ec5eaff9b064f47549fe1 /lib/PublicInbox/ViewDiff.pm | |
parent | fbe89926961e2e090481fa283048c31aaddc17cf (diff) | |
download | public-inbox-06600f6ea9258425f4f7ff7a7b1f3d028d11b638.tar.gz |
Avoid relying on $DIGIT captures when @- and @+ to access last match start and end, respectively. The elimination of the post capture ought to allow the use of sv_chop to advance the string start pointer without memory copies. This ought to save 1-2MB of memory on my system since I've noticed the captures was using a big chunk of scratchpad space.
Diffstat (limited to 'lib/PublicInbox/ViewDiff.pm')
-rw-r--r-- | lib/PublicInbox/ViewDiff.pm | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 9a7adb57..95bbf2d2 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -154,16 +154,16 @@ sub diff_header ($$$) { sub diff_before_or_after ($$) { my ($ctx, $x) = @_; - if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n" # \$1 - # diffstat lines: - ((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+) - (\x20[0-9]+\x20files?\x20)changed, - (.*?)\z/msx) { # notes, commit message, etc - my @x = ($4, $3, $2, $1); - undef $$x; + if (exists $ctx->{-anchors} && $$x =~ # diffstat lines: + /((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+) + (\x20[0-9]+\x20files?\x20)changed,/msx) { + my $pre = substr($$x, 0, $-[0]); # (likely) short prefix + substr($$x, 0, $+[0], ''); # sv_chop on $$x ($$x may be long) + my @x = ($2, $1); my $lnk = $ctx->{-linkify}; my $zfh = $ctx->{zfh}; - print $zfh $lnk->to_html(pop @x); # $1 uninteresting prefix + # uninteresting prefix + print $zfh $lnk->to_html($pre); for my $l (split(/^/m, pop(@x))) { # $2 per-file stat lines $l =~ /^ (.+)( +\| .*\z)/s and anchor0($ctx, $1, $2) and next; @@ -173,7 +173,7 @@ sub diff_before_or_after ($$) { print $zfh pop(@x), # $3 /^ \d+ files? / qq(<a href="$ch">changed</a>,), # insertions/deletions, notes, commit message, etc: - $lnk->to_html(@x); + $lnk->to_html($$x); } else { print { $ctx->{zfh} } $ctx->{-linkify}->to_html($$x); } |