From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 23C041F665 for ; Sat, 10 Sep 2022 08:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797936; bh=711CGA3CU7cKexpxLpOS/YGAaBGfferKFFQ5hG9ybJE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XqTclfOJ5EZntvMB9EYI5G8Dydlcg5IW54dODCejRNjpX4CMlPWVShyZEjCM0m14r A2+ywgL71fQbh+D1RBNFj1kenzWuLPpfNfdyJNEpvJSJNwdMK+owgIGzq0Idf2WpQn c2ZPCKMsniUm0ixnQ13aAFoGoA/JUiZgXknSkWA4= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 25/38] view: switch a few things to ctx->zmore Date: Sat, 10 Sep 2022 08:17:16 +0000 Message-Id: <20220910081729.2011934-26-e@80x24.org> In-Reply-To: <20220910081729.2011934-1-e@80x24.org> References: <20220910081729.2011934-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Unfortunately, this is actually slower. However, this hopefully makes it easier to improve the internals and make performance improvements down the line. --- lib/PublicInbox/View.pm | 14 +++++------- lib/PublicInbox/ViewDiff.pm | 45 +++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 2f99179e..3dbf8bac 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -560,7 +560,7 @@ sub add_text_body { # callback for each_part my ($part, $depth, $idx) = @$p; my $ct = $part->content_type || 'text/plain'; my $fn = $part->filename; - my $rv = $ctx->{obuf}; + my $rv = $ctx->{obuf} //= \(my $obuf = ''); my ($s, $err) = msg_part_text($part, $ct); $s // return $$rv .= (attach_link($ctx, $ct, $p, $fn) // ''); if ($part->{is_submsg}) { @@ -618,18 +618,16 @@ sub add_text_body { # callback for each_part $$rv .= "\n"; } delete $part->{bdy}; # save memory - foreach my $cur (@sections) { + for my $cur (@sections) { # $cur may be huge if ($cur =~ /\A>/) { # we use a here to allow users to specify # their own color for quoted text - $$rv .= qq(); - $$rv .= $l->to_html($cur); - $$rv .= ''; + $ctx->zmore(qq(), + $l->to_html($cur), ''); } elsif ($diff) { flush_diff($ctx, \$cur); - } else { - # regular lines, OK - $$rv .= $l->to_html($cur); + } else { # regular lines, OK + $ctx->zmore($l->to_html($cur)); } undef $cur; # free memory } diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 076aa1af..36601910 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -156,10 +156,7 @@ sub diff_header ($$$) { warn "BUG? <$$x> had no ^index line"; } $$x =~ s!^diff --git!anchor1($ctx, $pb) // 'diff --git'!ems; - my $dst = $ctx->{obuf}; - $$dst .= qq(); - $$dst .= $$x; - $$dst .= ''; + $ctx->zmore(qq($$x)); $dctx; } @@ -182,9 +179,10 @@ sub diff_before_or_after ($$) { my $ch = $ctx->{changed_href} // '#related'; $$x .= qq(changed,); $$x .= ascii_html(pop @x); # $4: insertions/deletions - $$x .= $lnk->to_html(pop @x); # notes, commit message, etc + # notes, commit message, etc + $ctx->zmore($$x .= $lnk->to_html(pop @x)); } else { - $ctx->{-linkify}->to_html($$x); + $ctx->zmore($ctx->{-linkify}->to_html($$x)); } } @@ -195,8 +193,7 @@ sub flush_diff ($$) { my @top = split($EXTRACT_DIFFS, $$cur); undef $$cur; # free memory - my $linkify = $ctx->{-linkify}; - my $dst = $ctx->{obuf}; + my $lnk = $ctx->{-linkify}; my $dctx; # {}, keys: Q, oid_a, oid_b while (defined(my $x = shift @top)) { @@ -223,28 +220,28 @@ sub flush_diff ($$) { if (!defined($dctx)) { $after .= $s; } elsif ($s =~ s/\A@@ (\S+) (\S+) @@//) { - $$dst .= qq(); - $$dst .= diff_hunk($dctx, $1, $2); - $$dst .= $linkify->to_html($s); - $$dst .= ''; - } elsif ($s =~ /\A\+/) { - $$dst .= qq(); - $$dst .= $linkify->to_html($s); - $$dst .= ''; + $ctx->zmore(qq() . + diff_hunk($dctx, $1, $2) . + $lnk->to_html($s) . + ''); + } elsif ($s =~ /\A\+/) { # $s may be huge + $ctx->zmore(qq(), + $lnk->to_html($s), + ''); } elsif ($s =~ /\A-- $/sm) { # email sig starts $dctx = undef; $after .= $s; - } elsif ($s =~ /\A-/) { - $$dst .= qq(); - $$dst .= $linkify->to_html($s); - $$dst .= ''; - } else { - $$dst .= $linkify->to_html($s); + } elsif ($s =~ /\A-/) { # $s may be huge + $ctx->zmore(qq(), + $lnk->to_html($s), + ''); + } else { # $s may be huge + $ctx->zmore($lnk->to_html($s)); } } - $$dst .= diff_before_or_after($ctx, \$after) if !$dctx; + diff_before_or_after($ctx, \$after) if !$dctx; } else { - $$dst .= diff_before_or_after($ctx, \$x); + diff_before_or_after($ctx, \$x); } } }