Skip to content

Commit

Permalink
improved Mojo::Content performance slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 13, 2012
1 parent e0bb7e8 commit 89c8775
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.48 2012-10-14
- Improved Mojo::Content performance slightly.

3.47 2012-10-13
- Added all method to Mojo::UserAgent::CookieJar.
- Improved documentation.
Expand Down
35 changes: 16 additions & 19 deletions lib/Mojo/Content.pm
Expand Up @@ -83,10 +83,7 @@ sub is_multipart {undef}

sub is_parsing_body { (shift->{state} // '') eq 'body' }

sub leftovers {
my $self = shift;
return ($self->{pre_buffer} // '') . ($self->{buffer} // '');
}
sub leftovers { shift->{buffer} }

sub parse {
my $self = shift;
Expand All @@ -96,21 +93,6 @@ sub parse {
return $self if $self->{state} eq 'headers';
$self->_body;

# No content
if ($self->skip_body) {
$self->{state} = 'finished';
return $self;
}

# Relaxed parsing
my $headers = $self->headers;
if ($self->auto_relax) {
my $connection = $headers->connection || '';
my $len = $headers->content_length // '';
$self->relaxed(1)
if !length $len && ($connection =~ /close/i || $headers->content_type);
}

# Parse chunked content
$self->{real_size} //= 0;
if ($self->is_chunked && $self->{state} ne 'headers') {
Expand All @@ -127,6 +109,21 @@ sub parse {
$self->{pre_buffer} = '';
}

# No content
if ($self->skip_body) {
$self->{state} = 'finished';
return $self;
}

# Relaxed parsing
my $headers = $self->headers;
if ($self->auto_relax) {
my $connection = $headers->connection || '';
my $len = $headers->content_length // '';
$self->relaxed(1)
if !length $len && ($connection =~ /close/i || $headers->content_type);
}

# Chunked or relaxed content
if ($self->is_chunked || $self->relaxed) {
$self->{size} += length($self->{buffer} //= '');
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -38,7 +38,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Rainbow';
our $VERSION = '3.47';
our $VERSION = '3.48';

sub AUTOLOAD {
my $self = shift;
Expand Down

0 comments on commit 89c8775

Please sign in to comment.