Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 5, 2012
1 parent cf3ce52 commit a94d2e1
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 27 deletions.
9 changes: 3 additions & 6 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -34,10 +34,7 @@ sub new {

sub b { __PACKAGE__->new(@_) }

sub clone {
my $self = shift;
return $self->new($$self);
}
sub clone { $_[0]->new(${$_[0]}) }

sub decode {
my $self = shift;
Expand All @@ -59,14 +56,14 @@ sub say {

sub secure_compare { Mojo::Util::secure_compare ${shift()}, @_ }

sub size { length ${shift()} }
sub size { length ${$_[0]} }

sub split {
my ($self, $pattern) = @_;
return Mojo::Collection->new(map { $self->new($_) } split $pattern, $$self);
}

sub to_string { ${shift()} }
sub to_string { ${$_[0]} }

1;

Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -161,10 +161,7 @@ sub start {
(ref $self ? $self : $self->singleton)->reactor->start;
}

sub stop {
my $self = shift;
(ref $self ? $self : $self->singleton)->reactor->stop;
}
sub stop { (ref $_[0] ? $_[0] : $_[0]->singleton)->reactor->stop }

sub stream {
my ($self, $stream) = @_;
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -110,10 +110,7 @@ sub start {
$self->{handle} => sub { $self->_accept for 1 .. $self->multi_accept });
}

sub stop {
my $self = shift;
$self->reactor->remove($self->{handle});
}
sub stop { $_[0]->reactor->remove($_[0]->{handle}) }

sub _accept {
my $self = shift;
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -240,7 +240,8 @@ sub _decode_value {
}

sub _encode_array {
return '[' . join(',', map { _encode_values($_) } @{shift()}) . ']';
my $array = shift;
return '[' . join(',', map { _encode_values($_) } @$array) . ']';
}

sub _encode_object {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Reactor/Poll.pm
Expand Up @@ -69,7 +69,7 @@ sub recurring { shift->_timer(1, @_) }

sub remove {
my ($self, $remove) = @_;
return !!delete shift->{timers}{shift()} unless ref $remove;
return !!delete $self->{timers}{$remove} unless ref $remove;
$self->_poll->remove($remove);
return !!delete $self->{io}{fileno $remove};
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/Transaction.pm
Expand Up @@ -77,10 +77,7 @@ sub server_close {
sub server_read { croak 'Method "server_read" not implemented by subclass' }
sub server_write { croak 'Method "server_write" not implemented by subclass' }

sub success {
my $self = shift;
return $self->error ? undef : $self->res;
}
sub success { $_[0]->error ? undef : $_[0]->res }

1;

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -253,7 +253,7 @@ sub server_write {
return delete $self->{write} // '';
}

sub _challenge { b64_encode(sha1_bytes((pop() || '') . GUID), '') }
sub _challenge { b64_encode(sha1_bytes(($_[1] || '') . GUID), '') }

sub _message {
my ($self, $frame) = @_;
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -361,10 +361,7 @@ sub _handle {
$self->ioloop->stop if !$self->{nb} && !keys %{$self->{connections}};
}

sub _loop {
my $self = shift;
return $self->{nb} ? Mojo::IOLoop->singleton : $self->ioloop;
}
sub _loop { $_[0]->{nb} ? Mojo::IOLoop->singleton : $_[0]->ioloop }

sub _read {
my ($self, $id, $chunk) = @_;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -48,9 +48,9 @@ our @EXPORT_OK = (
qw(url_escape url_unescape xml_escape xor_encode)
);

sub b64_decode { decode_base64(shift) }
sub b64_decode { decode_base64($_[0]) }

sub b64_encode { encode_base64(shift, shift) }
sub b64_encode { encode_base64($_[0], $_[1]) }

sub camelize {
my $string = shift;
Expand Down

0 comments on commit a94d2e1

Please sign in to comment.