Skip to content

Commit

Permalink
use for loop instead of map for possible memory use reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Dec 29, 2009
1 parent 60145e6 commit c2ae857
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/Plack/Middleware.pm
Expand Up @@ -33,10 +33,12 @@ sub response_cb {
if (defined $filter_cb && ref $filter_cb eq 'CODE') {
Plack::Util::header_remove($res->[1], 'Content-Length');
if (defined $res->[2]) {
my $body = $res->[2];
if (ref $body eq 'ARRAY') {
$res->[2] = [ map $filter_cb->($_), @$body ];
if (ref $res->[2] eq 'ARRAY') {
for my $line (@{$res->[2]}) {
$line = $filter_cb->($line);
}
} else {
my $body = $res->[2];
my $getline = sub { $body->getline };
$res->[2] = Plack::Util::inline_object
getline => sub { $filter_cb->($getline->()) },
Expand Down
2 changes: 1 addition & 1 deletion t/Plack-Middleware/simple_content_filter.t
Expand Up @@ -4,7 +4,7 @@ use Plack::Test;
use Plack::Builder;

my $app = sub {
return [ 200, [ 'Content-Type' => 'text/plain', 'Content-Length' => 9 ], [ 'Hello Foo' ] ];
return [ 200, [ 'Content-Type' => 'text/plain', 'Content-Length' => 9 ], [ 'Hello ', 'Foo' ] ];
};

$app = builder {
Expand Down

0 comments on commit c2ae857

Please sign in to comment.