From 89a2237b49cac7690582c5ada1ed3466d0f57944 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 20 Aug 2015 02:30:30 +0000 Subject: search: avoid needless decode Email::MIME should handle everything for us and make things work nicely with Xapian (assuming I understand how encoding works in Perl). While we're at it, reduce temporary strings and arrays by using destructive operations and clobbering parts as we iterate through them. --- lib/PublicInbox/Search.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index c28401bc..aa29ae53 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -6,7 +6,6 @@ use strict; use warnings; use PublicInbox::SearchMsg; use Search::Xapian qw/:standard/; -require PublicInbox::View; use Email::MIME; use PublicInbox::MID qw/mid_clean mid_compressed/; @@ -88,7 +87,6 @@ sub add_message { my $mid = mid_compressed($mid_orig); my $was_ghost = 0; my $ct_msg = $mime->header('Content-Type') || 'text/plain'; - my $enc_msg = PublicInbox::View::enc_for($ct_msg); eval { my $smsg = $self->lookup_message($mid); @@ -151,9 +149,11 @@ sub add_message { # account for filter bugs... $ct =~ m!\btext/plain\b!i or return; - my $enc = PublicInbox::View::enc_for($ct, $enc_msg); my (@orig, @quot); - foreach my $l (split(/\n/, $enc->decode($part->body))) { + my $body = $part->body; + $part->body_set(''); + my @lines = split(/\n/, $body); + while (defined(my $l = shift @lines)) { if ($l =~ /^\s*>/) { push @quot, $l; } else { @@ -162,10 +162,12 @@ sub add_message { } if (@quot) { $tg->index_text(join("\n", @quot), 0); + @quot = (); $tg->increase_termpos; } if (@orig) { $tg->index_text(join("\n", @orig)); + @orig = (); $tg->increase_termpos; } }); -- cgit v1.2.3-24-ge0c7