dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] mbox: reduce callers of Email::Simple->new
@ 2016-08-07  0:34 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-08-07  0:34 UTC (permalink / raw)
  To: spew

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', "<mailto:$ibx->{-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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-07  0:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-07  0:34 [PATCH] mbox: reduce callers of Email::Simple->new Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).