From a4f7622064f71c02102cb17fce0b4e67782059fc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 23 Aug 2015 20:05:41 +0000 Subject: [PATCH] cleanup calls to header_obj 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 9af92793..719398f7 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 2c2f8193..05bf3465 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 f4e72826..f9081a6d 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 ? " index" : ''; 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 = " ". -- 2.44.0