diff options
author | Eric Wong <e@yhbt.net> | 2020-06-10 07:04:19 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-06-13 07:55:45 +0000 |
commit | 05978869826c50252d49a7977470ee3107eb2d16 (patch) | |
tree | 3f760eb01af3f6ec5f68411584d8a19e4c6b6521 /lib | |
parent | 1804e2961f3a28045b601a982f44ff61ea33a2fe (diff) | |
download | public-inbox-05978869826c50252d49a7977470ee3107eb2d16.tar.gz |
While we can't memoize the regexp forever like we do with other Eml users, we can still benefit from caching regexp compilation on a per-request basis. A FETCH request from mutt on a 4K message inbox is around 8% faster after this. Since regexp compilation via qr// isn't unbearably slow, a shared cache probably isn't worth the trouble of implementing. A per-request cache seems enough.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/IMAP.pm | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 0852ffab..39667199 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -544,25 +544,23 @@ sub hdrs_regexp ($) { # BODY[($SECTION_IDX.)?HEADER.FIELDS.NOT ($HDRS)]<$offset.$bytes> sub partial_hdr_not { - my ($eml, $section_idx, $hdrs) = @_; + my ($eml, $section_idx, $hdrs_re) = @_; if (defined $section_idx) { $eml = eml_body_idx($eml, $section_idx) or return; } my $str = $eml->header_obj->as_string; - my $re = hdrs_regexp($hdrs); - $str =~ s/$re//g; + $str =~ s/$hdrs_re//g; $str .= "\r\n"; } # BODY[($SECTION_IDX.)?HEADER.FIELDS ($HDRS)]<$offset.$bytes> sub partial_hdr_get { - my ($eml, $section_idx, $hdrs) = @_; + my ($eml, $section_idx, $hdrs_re) = @_; if (defined $section_idx) { $eml = eml_body_idx($eml, $section_idx) or return; } my $str = $eml->header_obj->as_string; - my $re = hdrs_regexp($hdrs); - join('', ($str =~ m/($re)/g), "\r\n"); + join('', ($str =~ m/($hdrs_re)/g), "\r\n"); } sub partial_prepare ($$$) { @@ -583,9 +581,10 @@ sub partial_prepare ($$$) { (?:HEADER\.FIELDS(\.NOT)?)\x20 # 2 \(([A-Z0-9\-\x20]+)\) # 3 - hdrs \](?:<([0-9]+)(?:\.([0-9]+))?>)?\z/sx) { # 4 5 - $partial->{$att} = [ $2 ? \&partial_hdr_not - : \&partial_hdr_get, - $1, $3, $4, $5 ]; + my $tmp = $partial->{$att} = [ $2 ? \&partial_hdr_not + : \&partial_hdr_get, + $1, undef, $4, $5 ]; + $tmp->[2] = hdrs_regexp($3); } else { undef; } |