From: Eric Wong <e@80x24.org>
Date: Sat, 10 Sep 2022 08:17:03 +0000 (+0000)
Subject: view: eml_entry: reduce manipulation of ctx->{obuf}
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=7946a7fce008989458a28641cc899c8bbd99c2c4;p=public-inbox.git

view: eml_entry: reduce manipulation of ctx->{obuf}

This is another step towards avoid unnecessary copies
and pad space waste.
---

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 3980ed91..37b484ae 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -246,11 +246,11 @@ sub eml_entry {
 	$ctx->{mhref} = $mhref;
 	$ctx->{changed_href} = "#e$id"; # for diffstat "files? changed,"
 	$ctx->{obuf} = \$rv;
-	$eml->each_part(\&add_text_body, $ctx, 1);
-	delete $ctx->{obuf};
+	$eml->each_part(\&add_text_body, $ctx, 1); # expensive
+	$ctx->zmore; # TODO: remove once add_text_body is updated
 
 	# add the footer
-	$rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
+	$rv = "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
 		"<a\nhref=\"$mhref\">permalink</a>" .
 		" <a\nhref=\"${mhref}raw\">raw</a>" .
 		" <a\nhref=\"${mhref}#R\">reply</a>";
@@ -388,7 +388,8 @@ sub pre_thread  { # walk_thread callback
 sub thread_eml_entry {
 	my ($ctx, $eml) = @_;
 	my ($beg, $end) = thread_adj_level($ctx, $ctx->{level});
-	$beg . '<pre>' . eml_entry($ctx, $eml) . '</pre>' . $end;
+	$ctx->zmore($beg.'<pre>');
+	eml_entry($ctx, $eml) . '</pre>' . $end;
 }
 
 sub next_in_queue ($$) {