Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

small optimizations

  • Loading branch information...
commit 506214be4d6994db87577323f5d84ec3bd835b86 1 parent 899af07
@kraih authored
View
2  lib/Mojo/Asset/Memory.pm
@@ -16,7 +16,7 @@ sub new { shift->SUPER::new(@_, content => '') }
sub add_chunk {
my ($self, $chunk) = @_;
- $self->{content} .= $chunk if defined $chunk;
+ $self->{content} .= $chunk // '';
return $self
if !$self->auto_upgrade || $self->size <= $self->max_memory_size;
my $file = Mojo::Asset::File->new;
View
11 lib/Mojo/Content.pm
@@ -165,15 +165,10 @@ sub parse_body_once {
sub parse_until_body {
my ($self, $chunk) = @_;
- # Prepare first buffer
- $self->{pre_buffer} //= '';
- $self->{raw_size} //= 0;
-
# Add chunk
- if (defined $chunk) {
- $self->{raw_size} += length $chunk;
- $self->{pre_buffer} .= $chunk;
- }
+ $chunk //= '';
+ $self->{raw_size} += length $chunk;
+ $self->{pre_buffer} .= $chunk;
# Parser started
unless ($self->{state}) {
View
7 lib/Mojo/Headers.pm
@@ -89,12 +89,11 @@ sub names {
}
sub parse {
- my ($self, $chunk) = @_;
+ my $self = shift;
# Parse headers with size limit
$self->{state} = 'headers';
- $self->{buffer} //= '';
- $self->{buffer} .= $chunk if defined $chunk;
+ $self->{buffer} .= shift // '';
my $headers = $self->{cache} ||= [];
my $max = $self->max_line_size;
while (defined(my $line = get_line \$self->{buffer})) {
@@ -106,7 +105,7 @@ sub parse {
}
# New header
- if ($line =~ /^(\S+)\s*:\s*(.*)$/) { push @$headers, $1, $2 }
+ elsif ($line =~ /^(\S+)\s*:\s*(.*)$/) { push @$headers, $1, $2 }
# Multiline
elsif (@$headers && $line =~ s/^\s+//) { $headers->[-1] .= " $line" }
View
9 lib/Mojo/Message.pm
@@ -339,12 +339,9 @@ sub _parse {
my ($self, $until_body, $chunk) = @_;
# Add chunk
- $self->{buffer} //= '';
- $self->{raw_size} //= 0;
- if (defined $chunk) {
- $self->{raw_size} += length $chunk;
- $self->{buffer} .= $chunk;
- }
+ $chunk //= '';
+ $self->{raw_size} += length $chunk;
+ $self->{buffer} .= $chunk;
# Check message size
return $self->error('Maximum message size exceeded.', 413)
View
2  lib/Mojo/Transaction/WebSocket.pm
@@ -239,7 +239,7 @@ sub server_read {
my ($self, $chunk) = @_;
# Parse frames
- $self->{read} .= $chunk if defined $chunk;
+ $self->{read} .= $chunk // '';
while (my $frame = $self->parse_frame(\$self->{read})) {
$self->emit(frame => $frame);
}
View
5 lib/Mojo/Util.pm
@@ -113,13 +113,12 @@ sub encode {
}
sub get_line {
- my $stringref = shift;
# Locate line ending
- return if (my $pos = index $$stringref, "\x0a") == -1;
+ return if (my $pos = index ${$_[0]}, "\x0a") == -1;
# Extract line and ending
- my $line = substr $$stringref, 0, $pos + 1, '';
+ my $line = substr ${$_[0]}, 0, $pos + 1, '';
$line =~ s/\x0d?\x0a$//;
return $line;
Please sign in to comment.
Something went wrong with that request. Please try again.