user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/8] view: remove mhref arg from multipart_text_as_html
Date: Sat, 15 Feb 2020 09:46:33 +0000
Message-ID: <20200215094640.19425-2-e@yhbt.net> (raw)
In-Reply-To: <20200215094640.19425-1-e@yhbt.net>

No point in passing something on stack only to stash it
into the $ctx which holds most other parameters used for
rendering the HTML.
---
 lib/PublicInbox/View.pm          | 14 +++++++-------
 lib/PublicInbox/WwwAtomStream.pm |  3 ++-
 xt/perf-msgview.t                |  3 ++-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index d097d8ab..dcaee1ae 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -29,8 +29,9 @@ sub msg_page_i {
 	my $more = $ctx->{more};
 	if ($nr == 1) {
 		# $more cannot be true w/o $smsg being defined:
-		my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
-		multipart_text_as_html(delete $ctx->{mime}, $upfx, $ctx);
+		$ctx->{mhref} = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/'
+				      : '';
+		multipart_text_as_html(delete $ctx->{mime}, $ctx);
 		${delete $ctx->{obuf}} .= '</pre><hr>';
 	} elsif ($more) {
 		++$ctx->{end_nr};
@@ -83,10 +84,10 @@ sub msg_page_more {
 	my $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
 	$ctx->{more} = $next ? [ $id, $prev, $next ] : undef;
 	return '' unless $smsg;
-	my $upfx = '../' . mid_escape($smsg->mid) . '/';
+	$ctx->{mhref} = '../' . mid_escape($smsg->mid) . '/';
 	my $mime = delete $smsg->{mime};
 	_msg_page_prepare_obuf($mime->header_obj, $ctx, $nr);
-	multipart_text_as_html($mime, $upfx, $ctx);
+	multipart_text_as_html($mime, $ctx);
 	${delete $ctx->{obuf}} .= '</pre><hr>';
 }
 
@@ -486,11 +487,10 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback
 }
 
 sub multipart_text_as_html {
-	my (undef, $mhref, $ctx) = @_; # $mime = $_[0]
-	$ctx->{mhref} = $mhref;
+	# ($mime, $ctx) = @_; # msg_iter will do "$_[0] = undef"
 
 	# scan through all parts, looking for displayable text
-	msg_iter($_[0], \&add_text_body, $ctx, 1);
+	msg_iter($_[0], \&add_text_body, $_[1], 1);
 }
 
 sub flush_quote {
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index ea871fe5..658934a2 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -142,7 +142,8 @@ sub feed_entry {
 		qq{<div\nxmlns="http://www.w3.org/1999/xhtml">} .
 		qq(<pre\nstyle="white-space:pre-wrap">);
 	$ctx->{obuf} = \$s;
-	PublicInbox::View::multipart_text_as_html($mime, $href, $ctx);
+	$ctx->{mhref} = $href;
+	PublicInbox::View::multipart_text_as_html($mime, $ctx);
 	delete $ctx->{obuf};
 	$s .= '</pre></div></content></entry>';
 }
diff --git a/xt/perf-msgview.t b/xt/perf-msgview.t
index f676ca93..3ea92ec6 100644
--- a/xt/perf-msgview.t
+++ b/xt/perf-msgview.t
@@ -37,13 +37,14 @@ my $n = 0;
 my $t = timeit(1, sub {
 	my $obuf = '';
 	$ctx->{obuf} = \$obuf;
+	$ctx->{mhref} = '../';
 	while (<$fh>) {
 		($cmt, $type) = split / /;
 		next if $type ne 'blob';
 		++$n;
 		$str = $git->cat_file($cmt);
 		$mime = PublicInbox::MIME->new($str);
-		PublicInbox::View::multipart_text_as_html($mime, '../', $ctx);
+		PublicInbox::View::multipart_text_as_html($mime, $ctx);
 		$obuf = '';
 	}
 });

  reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-15  9:46 [PATCH 0/8] some view cleanups and minor bugfixes Eric Wong
2020-02-15  9:46 ` Eric Wong [this message]
2020-02-15  9:46 ` [PATCH 2/8] view: single id="t" for multi-Subject messages Eric Wong
2020-02-15  9:46 ` [PATCH 3/8] view: dump_topics: better naming of top Subject Eric Wong
2020-02-15  9:46 ` [PATCH 4/8] view: cleanup topic accumulation and dumping Eric Wong
2020-02-15  9:46 ` [PATCH 5/8] view,searchview: avoid smsg method calls when using SQLite/Xapian Eric Wong
2020-02-15  9:46 ` [PATCH 6/8] view: escape Subject HTML directly Eric Wong
2020-02-15  9:46 ` [PATCH 7/8] view: escape ampersand in Message-IDs Eric Wong
2020-02-15  9:46 ` [PATCH 8/8] view: remove last Hval->new caller Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200215094640.19425-2-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git