Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 3, 2012
1 parent 57a3cae commit 67fab50
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/Mojo/Headers.pm
Expand Up @@ -98,22 +98,19 @@ sub parse {
while (defined(my $line = get_line \$self->{buffer})) {

# Check line size limit
if (length $line > $max) {
$self->{limit} = $self->{state} = 'finished';
return $self;
}
return $self->tap(sub { $_->{limit} = $_->{state} = 'finished' })
if length $line > $max;

# New header
elsif ($line =~ /^(\S+)\s*:\s*(.*)$/) { push @$headers, $1, $2 }
if ($line =~ /^(\S+)\s*:\s*(.*)$/) { push @$headers, $1, $2 }

# Multiline
elsif (@$headers && $line =~ s/^\s+//) { $headers->[-1] .= " $line" }

# Empty line
else {
$self->add(splice @$headers, 0, 2) while @$headers;
$self->{state} = 'finished';
return $self;
return $self->tap(sub { $_->{state} = 'finished' });
}
}

Expand All @@ -128,8 +125,7 @@ sub referrer { scalar shift->header(Referer => @_) }

sub remove {
my ($self, $name) = @_;
delete $self->{headers}{lc $name};
return $self;
return $self->tap(sub { delete $_->{headers}{lc $name} });
}

sub to_hash {
Expand Down

0 comments on commit 67fab50

Please sign in to comment.