Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 22, 2013
1 parent 2529541 commit 94f3052
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
9 changes: 4 additions & 5 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -4,7 +4,6 @@ use Mojo::Base 'Mojo::EventEmitter';
# "Fry: Since when is the Internet about robbing people of their privacy?
# Bender: August 6, 1991."
use Carp 'croak';
use List::Util 'first';
use Mojo::IOLoop;
use Mojo::Server::Daemon;
use Mojo::URL;
Expand Down Expand Up @@ -52,15 +51,15 @@ for my $name (qw(http https no)) {
};
}

sub DESTROY { shift->_cleanup }

# DEPRECATED in Top Hat!
sub new {
my $self = shift->SUPER::new;
while (my $name = shift) { $self->$name(shift) }
return $self;
}

sub DESTROY { shift->_cleanup }

sub app {
my ($self, $app) = @_;

Expand Down Expand Up @@ -152,7 +151,7 @@ sub _cache {
my $max = $self->max_connections;
$self->_remove(shift(@$old)->[1]) while @$old > $max;
push @$old, [$name, $id] if $max;
return undef;
return;
}

# Dequeue
Expand All @@ -162,7 +161,7 @@ sub _cache {
for my $cached (@$old) {

# Search for id/name and remove corrupted connections
if (!$found && first { $_ eq $name } @$cached) {
if (!$found && grep { $_ eq $name } @$cached) {
next unless my $stream = $loop->stream($cached->[1]);
$stream->is_readable ? $stream->close : ($found = $cached->[1]);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/UserAgent/Proxy.pm
@@ -1,8 +1,6 @@
package Mojo::UserAgent::Proxy;
use Mojo::Base -base;

use List::Util 'first';

has [qw(http https not)];

sub detect {
Expand Down Expand Up @@ -31,7 +29,7 @@ sub inject {
}

sub is_needed {
!first { $_[1] =~ /\Q$_\E$/ } @{$_[0]->not || []};
!grep { $_[1] =~ /\Q$_\E$/ } @{$_[0]->not || []};
}

1;
Expand Down
3 changes: 1 addition & 2 deletions t/mojo/prefork.t
Expand Up @@ -10,7 +10,6 @@ use Test::More;
plan skip_all => 'set TEST_PREFORK to enable this test (developer only!)'
unless $ENV{TEST_PREFORK};

use List::Util 'first';
use Mojo::IOLoop;
use Mojo::Server::Prefork;
use Mojo::UserAgent;
Expand Down Expand Up @@ -57,7 +56,7 @@ my $cb = $prefork->app->log->on(message => sub { $log .= pop });
$prefork->run;
is scalar @spawn, 4, 'four workers spawned';
is scalar @reap, 4, 'four workers reaped';
ok !!first { $worker eq $_ } @spawn, 'worker has a heartbeat';
ok !!grep { $worker eq $_ } @spawn, 'worker has a heartbeat';
ok $graceful, 'server has been stopped gracefully';
is_deeply [sort @spawn], [sort @reap], 'same process ids';
is $tx->res->code, 200, 'right status';
Expand Down

0 comments on commit 94f3052

Please sign in to comment.