From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS12876 163.172.0.0/16 X-Spam-Status: No, score=-2.2 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL, TO_EQ_FM_DOM_SPF_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (torrelay5.tomhek.net [163.172.38.173]) by dcvr.yhbt.net (Postfix) with ESMTP id 0B6791F859 for ; Sun, 7 Aug 2016 00:34:15 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] mbox: reduce callers of Email::Simple->new Date: Sun, 7 Aug 2016 00:34:05 +0000 Message-Id: <20160807003405.21984-1-e@80x24.org> List-Id: Hopefully this also ought to allow us to recycle memory more quickly and reduce our commit charge. --- lib/PublicInbox/Mbox.pm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm index dc41548..a13e480 100644 --- a/lib/PublicInbox/Mbox.pm +++ b/lib/PublicInbox/Mbox.pm @@ -11,15 +11,14 @@ use URI::Escape qw/uri_escape_utf8/; require Email::Simple; sub emit1 { - my ($ctx, $msg) = @_; - $msg = Email::Simple->new($msg); # single message should be easily renderable in browsers - [200, ['Content-Type', 'text/plain'], [ msg_str($ctx, $msg)] ] + [200, ['Content-Type', 'text/plain'], [ msg_str(@_) ] ] } sub msg_str { - my ($ctx, $simple) = @_; # Email::Simple object - my $header_obj = $simple->header_obj; + my $ctx = $_[0]; + my $msg = $_[1] = Email::Simple->new($_[1]); + my $header_obj = $msg->header_obj; # drop potentially confusing headers, ssoma already should've dropped # Lines and Content-Length @@ -35,7 +34,7 @@ sub msg_str { 'List-Archive', "<$base>", 'List-Post', "{-primary_address}>", ); - my $crlf = $simple->crlf; + my $crlf = $msg->crlf; my $buf = "From mboxrd\@z Thu Jan 1 00:00:00 1970\n" . $header_obj->as_string; for (my $i = 0; $i < @append; $i += 2) { @@ -54,7 +53,7 @@ sub msg_str { # mboxrd quoting style # ref: http://www.qmail.org/man/man5/mbox.html - my $body = $simple->body; + my $body = $msg->body; $body =~ s/^(>*From )/>$1/gm; $buf .= $body; $buf .= "\n"; @@ -130,7 +129,6 @@ sub getline { do { while (defined(my $smsg = shift @{$self->{msgs}})) { my $msg = eval { $ibx->msg_by_smsg($smsg) } or next; - $msg = Email::Simple->new($msg); $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg)); my $bref = $self->{buf}; if (length($$bref) >= 8192) { -- EW