From: Eric Wong Date: Sun, 7 Jul 2024 06:01:58 +0000 (+0000) Subject: www: replace *eml_entry with *emit_eml X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18f41f5af397f903898154591de2cd1cd514c920;p=thirdparty%2Fpublic-inbox.git www: replace *eml_entry with *emit_eml This further reduces the amount of copies, temporary strings, and scratchpad use started way back in 2022. With a 700+ message thread on a /T/ endpoint, this saves roughly 1-2% time and roughly 100 KB of memory. --- diff --git a/Documentation/mknews.perl b/Documentation/mknews.perl index 001ad3102..da29cfac9 100755 --- a/Documentation/mknews.perl +++ b/Documentation/mknews.perl @@ -111,8 +111,8 @@ sub mime2html { my ($out, $eml, $ctx) = @_; my $smsg = $ctx->{smsg} = bless {}, 'PublicInbox::Smsg'; $smsg->populate($eml); - $ctx->{msgs} = [ 1 ]; # for
in eml_entry - print $out PublicInbox::View::eml_entry($ctx, $eml) or die; + $ctx->{msgs} = [ 1 ]; # for
in emit_eml + PublicInbox::View::emit_eml $ctx, $eml; } sub html_start { diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 225565f40..a1c1d4d64 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -45,14 +45,15 @@ sub generate_html_index { sub new_html_i { my ($ctx, $eml) = @_; - print { $ctx->zfh } $ctx->html_top if exists $ctx->{-html_tip}; + my $zfh = $ctx->zfh; + print $zfh $ctx->html_top if exists $ctx->{-html_tip}; if ($eml) { $ctx->{smsg}->populate($eml) if !$ctx->{ibx}->{over}; - return PublicInbox::View::eml_entry($ctx, $eml); + return PublicInbox::View::emit_eml $ctx, $eml; } my $smsg = shift @{$ctx->{msgs}} or - print { $ctx->zfh } PublicInbox::View::pagination_footer( + print $zfh PublicInbox::View::pagination_footer( $ctx, './new.html'); $smsg; } diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index f056dddfa..3729c27bb 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -345,10 +345,11 @@ EOM # callback for PublicInbox::WwwStream::getline sub mset_thread_i { my ($ctx, $eml) = @_; - print { $ctx->zfh } $ctx->html_top if exists $ctx->{-html_tip}; - $eml and return PublicInbox::View::eml_entry($ctx, $eml); + my $zfh = $ctx->zfh; + print $zfh $ctx->html_top if exists $ctx->{-html_tip}; + $eml and return PublicInbox::View::emit_eml $ctx, $eml; my $smsg = shift @{$ctx->{msgs}} or - print { $ctx->zfh } @{delete($ctx->{skel})}; + print $zfh @{delete($ctx->{skel})}; $smsg; } diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 9a90f939a..ce8fa8659 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -240,9 +240,9 @@ sub to_cc_html ($$$$) { ($html, $len + $line_len); } -# Displays the text of of the message for /$INBOX/$MSGID/[Tt]/ endpoint -# this is already inside a
-sub eml_entry {
+# Spews the text of of the message for /$INBOX/$MSGID/[Tt]/ endpoint
+# to ctx->{zfh}, this is already inside a 
+sub emit_eml ($$) {
 	my ($ctx, $eml) = @_;
 	my $smsg = delete $ctx->{smsg};
 	my $subj = delete $smsg->{subject};
@@ -252,14 +252,13 @@ sub eml_entry {
 	my $root_anchor = $ctx->{root_anchor} || '';
 	my $irt;
 	my $obfs_ibx = $ctx->{-obfs_ibx};
-
 	$subj = '(no subject)' if $subj eq '';
-	my $rv = "* ";
 	$subj = ''.ascii_html($subj).'';
 	obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;
 	$subj = "$subj" if $root_anchor eq $id_m;
-	$rv .= $subj . "\n";
-	$rv .= _th_index_lite($mid_raw, \$irt, $id, $ctx);
+	my $zfh = $ctx->{zfh} // die 'BUG: no {zfh}';
+	print $zfh "* ',
+		$subj, "\n", _th_index_lite($mid_raw, \$irt, $id, $ctx);
 	my @tocc;
 	my $ds = delete $smsg->{ds}; # for v1 non-Xapian/SQLite users
 
@@ -269,55 +268,53 @@ sub eml_entry {
 
 	my $from = _hdr_names_html($eml, 'From');
 	obfuscate_addrs($obfs_ibx, $from) if $obfs_ibx;
-	$rv .= "From: $from @ ".fmt_ts($ds)." UTC";
 	my $upfx = $ctx->{-upfx};
 	my $mhref = $upfx . mid_href($mid_raw) . '/';
-	$rv .= qq{ (permalink / };
-	$rv .= qq{raw)\n};
-	my ($to, $tlen) = to_cc_html($ctx, $eml, 'To', $t);
-	my ($cc, $clen) = to_cc_html($ctx, $eml, 'Cc', $t);
-	my $to_cc = '';
-	if (($tlen + $clen) > COLS) {
-		$to_cc .= '  To: '.$to."\n" if $tlen;
-		$to_cc .= '  Cc: '.$cc."\n" if $clen;
-	} else {
-		if ($tlen) {
-			$to_cc .= '  To: '.$to;
-			$to_cc .= '; +Cc: '.$cc if $clen;
+	say $zfh 'From: ', $from, ' @ ', fmt_ts($ds), qq[ UTC (permalink / raw';
+	{
+		my ($to, $tlen) = to_cc_html($ctx, $eml, 'To', $t);
+		my ($cc, $clen) = to_cc_html($ctx, $eml, 'Cc', $t);
+		my $to_cc = '';
+		if (($tlen + $clen) > COLS) {
+			$to_cc .= '  To: '.$to."\n" if $tlen;
+			$to_cc .= '  Cc: '.$cc."\n" if $clen;
 		} else {
-			$to_cc .= '  Cc: '.$cc if $clen;
+			if ($tlen) {
+				$to_cc .= '  To: '.$to;
+				$to_cc .= '; +Cc: '.$cc if $clen;
+			} else {
+				$to_cc .= '  Cc: '.$cc if $clen;
+			}
+			$to_cc .= "\n";
 		}
-		$to_cc .= "\n";
+		obfuscate_addrs($obfs_ibx, $to_cc) if $obfs_ibx;
+		print $zfh $to_cc;
 	}
-	obfuscate_addrs($obfs_ibx, $to_cc) if $obfs_ibx;
-	$rv .= $to_cc;
-
 	my $mapping = $ctx->{mapping};
 	if (!$mapping && (defined($irt) || defined($irt = in_reply_to($eml)))) {
-		my $href = $upfx . mid_href($irt) . '/';
-		my $html = ascii_html($irt);
-		$rv .= qq(In-Reply-To: <$html>\n)
+		print $zfh qq(In-Reply-To: <', ascii_html($irt), ">\n";
 	}
-	say { $ctx->zfh } $rv;
-
+	print $zfh "\n";
 	# scan through all parts, looking for displayable text
 	$ctx->{mhref} = $mhref;
 	$ctx->{changed_href} = "#e$id"; # for diffstat "files? changed,"
 	$eml->each_part(\&add_text_body, $ctx, 1); # expensive
 
 	# add the footer
-	$rv = "\n^ ".
-		"permalink" .
-		" raw" .
-		" reply";
+	print $zfh "\n^ permalink raw reply];
 
 	# points to permalink
 	delete($ctx->{-qry_dfblob}) and
-		$rv .= qq[ related];
+		print $zfh qq[ related];
 
 	my $hr;
 	if (defined(my $pct = $smsg->{pct})) { # used by SearchView.pm
-		$rv .= "\t[relevance $pct%]";
+		print $zfh "\t[relevance $pct%]";
 		$hr = 1;
 	} elsif ($mapping) {
 		my $nested = 'nested';
@@ -328,16 +325,16 @@ sub eml_entry {
 		} else {
 			$nested = "$nested";
 		}
-		$rv .= "\t[$flat";
-		$rv .= "|$nested]";
-		$rv .= " $ctx->{s_nr}";
+		print $zfh qq(\t[', $flat,
+			qq(|', $nested,
+			qq(] ', $ctx->{s_nr}, '';
 	} else {
 		$hr = $ctx->{-hr};
 	}
 
 	# do we have more messages? start a new 
 if so
-	$rv .= scalar(@{$ctx->{msgs}}) ? '

' : '
' if $hr; - $rv; + print $zfh (@{$ctx->{msgs}}) ? '

' : '
' if $hr; + ''; # FIXME: compat } sub pad_link ($$;$) { @@ -442,12 +439,14 @@ sub pre_thread { # walk_thread callback skel_dump($ctx, $level, $node); } -sub thread_eml_entry { +sub thread_emit_eml ($$) { my ($ctx, $eml) = @_; my ($beg, $end) = thread_adj_level($ctx, $ctx->{level}); - print { $ctx->zfh } $beg, '
';
-	print { $ctx->{zfh} } eml_entry($ctx, $eml), '
'; - $end; + my $zfh = $ctx->zfh; + print $zfh $beg, '
';
+	emit_eml $ctx, $eml;
+	print $zfh '
', $end; + ''; # FIXME: compat } sub next_in_queue ($$) { @@ -463,7 +462,7 @@ sub next_in_queue ($$) { sub stream_thread_i { # PublicInbox::WwwStream::getline callback my ($ctx, $eml) = @_; - return thread_eml_entry($ctx, $eml) if $eml; + return thread_emit_eml $ctx, $eml if $eml; return unless exists($ctx->{skel}); my $ghost_ok = $ctx->{nr}++; while (1) { @@ -552,11 +551,12 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback my ($ctx, $eml) = @_; if ($eml) { my $smsg = $ctx->{smsg}; + my $zfh = $ctx->zfh; if (exists $ctx->{-html_tip}) { $ctx->{-title_html} = ascii_html($smsg->{subject}); - print { $ctx->zfh } $ctx->html_top; + print $zfh $ctx->html_top; } - return eml_entry($ctx, $eml); + emit_eml $ctx, $eml; } else { while (my $smsg = shift @{$ctx->{msgs}}) { return $smsg if exists($smsg->{blob});