unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] cleanup calls to header_obj
@ 2015-08-23 22:35 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-23 22:35 UTC (permalink / raw)
  To: meta

Dereference header_obj only once when performance may be
critical, or simplify our code by calling "header" directly on
the Email::{Simple,MIME} object if not.
---
 lib/PublicInbox/Mbox.pm      | 5 +++--
 lib/PublicInbox/SearchIdx.pm | 8 ++++----
 lib/PublicInbox/View.pm      | 4 ++--
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 9af9279..719398f 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -27,14 +27,15 @@ sub emit1 {
 
 sub emit_msg {
 	my ($fh, $simple) = @_; # Email::Simple object
+	my $header_obj = $simple->header_obj;
 
 	# drop potentially confusing headers, ssoma already should've dropped
 	# Lines and Content-Length
 	foreach my $d (qw(Lines Content-Length Status)) {
-		$simple->header_set($d);
+		$header_obj->header_set($d);
 	}
 
-	my $buf = $simple->header_obj->as_string;
+	my $buf = $header_obj->as_string;
 	unless ($buf =~ /\AFrom /) {
 		$fh->write("From mboxrd\@z Thu Jan  1 00:00:00 1970\n");
 	}
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 2c2f819..05bf346 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -41,7 +41,7 @@ sub add_message {
 	my $db = $self->{xdb};
 
 	my $doc_id;
-	my $mid_orig = mid_clean($mime->header_obj->header('Message-ID'));
+	my $mid_orig = mid_clean($mime->header('Message-ID'));
 	my $mid = mid_compressed($mid_orig);
 	my $was_ghost = 0;
 	my $ct_msg = $mime->header('Content-Type') || 'text/plain';
@@ -208,9 +208,9 @@ sub link_message_to_parents {
 	my $doc = $smsg->{doc};
 	my $mid = mid_compressed($smsg->mid);
 	my $mime = $smsg->mime;
-	my $refs = $mime->header_obj->header('References');
+	my $refs = $mime->header('References');
 	my @refs = $refs ? ($refs =~ /<([^>]+)>/g) : ();
-	my $irt = $mime->header_obj->header('In-Reply-To');
+	my $irt = $mime->header('In-Reply-To');
 	if ($irt) {
 		$irt = mid_compressed(mid_clean($irt));
 
@@ -273,7 +273,7 @@ sub index_blob {
 sub unindex_blob {
 	my ($self, $git, $blob) = @_;
 	my $mime = do_cat_mail($git, $blob) or return;
-	my $mid = $mime->header_obj->header('Message-ID');
+	my $mid = $mime->header('Message-ID');
 	eval { $self->remove_message($mid) } if defined $mid;
 	warn "W: unindex_blob $blob: $@\n" if $@;
 }
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index f4e7282..f9081a6 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -420,7 +420,7 @@ sub html_footer {
 
 	my $subj = $mime->header('Subject') || '';
 	$subj = "Re: $subj" unless $subj =~ /\bRe:/;
-	my $mid = $mime->header_obj->header('Message-ID');
+	my $mid = $mime->header('Message-ID');
 	my $irt = uri_escape_utf8($mid);
 	delete $cc{$to};
 	$to = uri_escape_utf8($to);
@@ -431,7 +431,7 @@ sub html_footer {
 
 	my $idx = $standalone ? " <a\nhref=\"../\">index</a>" : '';
 	if ($idx && $srch) {
-		$irt = $mime->header_obj->header('In-Reply-To') || '';
+		$irt = $mime->header('In-Reply-To') || '';
 		$mid = mid_compressed(mid_clean($mid));
 		my $t_anchor = length $irt ? T_ANCHOR : '';
 		$idx = " <a\nhref=\"../t/$mid.html$t_anchor\">".
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-23 22:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-23 22:35 [PATCH] cleanup calls to header_obj Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).