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 320494e commit cf3ce52
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 31 deletions.
5 changes: 1 addition & 4 deletions lib/Mojo/Asset.pm
Expand Up @@ -12,10 +12,7 @@ sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' }

sub is_file {undef}

sub is_range {
my $self = shift;
return !!($self->end_range || $self->start_range);
}
sub is_range { !!($_[0]->end_range || $_[0]->start_range) }

sub move_to { croak 'Method "move_to" not implemented by subclass' }
sub size { croak 'Method "size" not implemented by subclass' }
Expand Down
14 changes: 3 additions & 11 deletions lib/Mojo/Content.pm
Expand Up @@ -76,10 +76,7 @@ sub is_chunked { !!shift->headers->transfer_encoding }

sub is_compressed { (shift->headers->content_encoding || '') =~ /^gzip$/i }

sub is_dynamic {
my $self = shift;
return $self->{dynamic} && !defined $self->headers->content_length;
}
sub is_dynamic { $_[0]->{dynamic} && !defined $_[0]->headers->content_length }

sub is_finished { (shift->{state} // '') eq 'finished' }

Expand All @@ -97,7 +94,7 @@ sub parse {
# Parse headers
$self->_parse_until_body(@_);
return $self if $self->{state} eq 'headers';
$self->_body;
$self->emit('body') unless $self->{body}++;

# Parse chunked content
$self->{real_size} //= 0;
Expand Down Expand Up @@ -203,11 +200,6 @@ sub write_chunk {
return $self;
}

sub _body {
my $self = shift;
$self->emit('body') unless $self->{body}++;
}

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

Expand Down Expand Up @@ -302,7 +294,7 @@ sub _parse_headers {
# Take care of leftovers
my $leftovers = $self->{pre_buffer} = $headers->leftovers;
$self->{header_size} = $self->{raw_size} - length $leftovers;
$self->_body;
$self->emit('body') unless $self->{body}++;
}

sub _parse_until_body {
Expand Down
11 changes: 2 additions & 9 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -107,15 +107,8 @@ sub delay {

sub generate_port { Mojo::IOLoop::Server->generate_port }

sub is_running {
my $self = shift;
return (ref $self ? $self : $self->singleton)->reactor->is_running;
}

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

sub recurring {
my ($self, $after, $cb) = @_;
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Log.pm
Expand Up @@ -46,9 +46,8 @@ sub is_fatal { shift->is_level('fatal') }
sub is_info { shift->is_level('info') }

sub is_level {
my $self = shift;
my $level = lc shift;
return $LEVEL->{$level} >= $LEVEL->{$ENV{MOJO_LOG_LEVEL} || $self->level};
my ($self, $level) = @_;
return $LEVEL->{lc $level} >= $LEVEL->{$ENV{MOJO_LOG_LEVEL} || $self->level};
}

sub is_warn { shift->is_level('warn') }
Expand Down
5 changes: 1 addition & 4 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -79,10 +79,7 @@ sub has_websocket {
return $parent->is_websocket;
}

sub is_endpoint {
my $self = shift;
return $self->inline ? undef : !@{$self->children};
}
sub is_endpoint { $_[0]->inline ? undef : !@{$_[0]->children} }

sub is_websocket { !!shift->{websocket} }

Expand Down

0 comments on commit cf3ce52

Please sign in to comment.