X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FEml.pm;h=f022516c12cd091cd2ee6bc77212208f399b7522;hp=80e7c1afe90db6dd4e7753c5cbe516997ba53c9c;hb=e07a58aa1a1118b2aeb75e674c3542ae5d93b2c9;hpb=1e64f2f0450477ffbb95b887511bdeec28e30ab0 diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 80e7c1af..f022516c 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -71,10 +71,18 @@ sub re_memo ($) { # compatible with our uses of Email::MIME sub new { my $ref = ref($_[1]) ? $_[1] : \(my $cpy = $_[1]); - if ($$ref =~ /\r?\n(\r?\n)/s) { # likely - # This can modify $$ref in-place and to avoid memcpy/memmove - # on a potentially large $$ref. It does need to make a - # copy for $hdr, though. Idea stolen from Email::Simple + # substr() can modify the first arg in-place and to avoid + # memcpy/memmove on a potentially large scalar. It does need + # to make a copy for $hdr, though. Idea stolen from Email::Simple. + + # We also prefer index() on common LFLF emails since it's faster + # and re scan can bump RSS by length($$ref) on big strings + if (index($$ref, "\r\n") < 0 && (my $pos = index($$ref, "\n\n")) >= 0) { + # likely on *nix + my $hdr = substr($$ref, 0, $pos + 2, ''); # sv_chop on $$ref + chop($hdr); # lower SvCUR + bless { hdr => \$hdr, crlf => "\n", bdy => $ref }, __PACKAGE__; + } elsif ($$ref =~ /\r?\n(\r?\n)/s) { my $hdr = substr($$ref, 0, $+[0], ''); # sv_chop on $$ref substr($hdr, -(length($1))) = ''; # lower SvCUR bless { hdr => \$hdr, crlf => $1, bdy => $ref }, __PACKAGE__;