Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 20, 2013
1 parent 894cf80 commit c7b4d67
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

3.83 2013-01-20
3.83 2013-01-21
- Improved documentation.
- Improved tests.

3.82 2013-01-18
- Improved documentation.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/Content.pm
Expand Up @@ -44,7 +44,7 @@ sub generate_body_chunk {
$self->emit(drain => $offset)
if !delete $self->{delay} && !length($self->{body_buffer} // '');

# Get chunk
# Empty buffer
my $chunk = delete $self->{body_buffer} // '';

# EOF or delay
Expand Down Expand Up @@ -171,10 +171,10 @@ sub write {
$self->{dynamic} = 1;
if (defined $chunk) { $self->{body_buffer} .= $chunk }

# Delay
# Delay content generation
else { $self->{delay} = 1 }

# Drain
# Add one-time drain event
$self->once(drain => $cb) if $cb;
$self->{eof} = 1 if defined $chunk && $chunk eq '';

Expand Down Expand Up @@ -260,7 +260,7 @@ sub _parse_chunked {
sub _parse_chunked_trailing_headers {
my $self = shift;

# Parse
# Parse and empty buffer
my $headers = $self->headers->parse(delete $self->{pre_buffer});
return unless $headers->is_finished;
$self->{chunk_state} = 'finished';
Expand All @@ -273,7 +273,7 @@ sub _parse_chunked_trailing_headers {
sub _parse_headers {
my $self = shift;

# Parse
# Parse and empty buffer
my $headers = $self->headers->parse(delete $self->{pre_buffer});
return unless $headers->is_finished;
$self->{state} = 'body';
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -78,7 +78,7 @@ sub get_body_chunk {
my $len = $boundary_len - 2;
return substr "--$boundary\x0d\x0a", $offset if $len > $offset;

# Parts
# Prepare content part by part
my $parts = $self->parts;
for (my $i = 0; $i < @$parts; $i++) {
my $part = $parts->[$i];
Expand Down Expand Up @@ -172,7 +172,7 @@ sub _parse_multipart_preamble {
sub _read {
my ($self, $chunk) = @_;

# Parse
# Buffer chunk and parse multipart content
$self->{multipart} .= $chunk;
my $boundary = $self->boundary;
until (($self->{multi_state} //= 'multipart_preamble') eq 'finished') {
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -48,7 +48,7 @@ sub acceptor {
weaken $acceptor->reactor($self->reactor)->{reactor};
$self->{accepts} = $self->max_accepts if $self->max_accepts;

# Stop accepting
# Stop accepting so new acceptor can get picked up
$self->_not_accepting;

return $id;
Expand Down Expand Up @@ -144,7 +144,7 @@ sub server {
if defined $self->{accepts}
&& ($self->{accepts} -= int(rand 2) + 1) <= 0;

# Stop accepting
# Stop accepting to release accept mutex
$self->_not_accepting;
}
);
Expand Down Expand Up @@ -273,7 +273,7 @@ sub _stream {
$self->{connections}{$id}{stream} = $stream;
weaken $stream->reactor($self->reactor)->{reactor};

# Stream
# Start streaming
weaken $self;
$stream->on(close => sub { $self->{connections}{$id}{finish} = 1 });
$stream->start;
Expand Down
7 changes: 1 addition & 6 deletions lib/Mojo/Message.pm
Expand Up @@ -44,7 +44,7 @@ sub body_params {
my $self = shift;
return $self->{body_params} if $self->{body_params};

# Charset
# Detect charset
my $params = $self->{body_params} = Mojo::Parameters->new;
$params->charset($self->content->charset || $self->default_charset);

Expand Down Expand Up @@ -198,7 +198,6 @@ sub parse {
return $self->error('Maximum line size exceeded', 431)
if $len > $self->max_line_size;

# Extract
$self->{state} = 'content' if $self->extract_start_line(\$self->{buffer});
}

Expand Down Expand Up @@ -235,11 +234,7 @@ sub upload {
sub uploads {
my $self = shift;

# Only multipart messages have uploads
my @uploads;
return \@uploads unless $self->is_multipart;

# Extract formdata
my $formdata = $self->_parse_formdata;
for my $data (@$formdata) {
my ($name, $filename, $part) = @$data;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -944,7 +944,7 @@ a new C<handler> when C<register> is called.
$app->renderer->add_handler(mine => sub {
my ($renderer, $c, $output, $options) = @_;

# Check for one time use inline template
# Check for one-time use inline template
my $inline = $options->{inline};

# Check for absolute template path
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/eventemitter.t
Expand Up @@ -61,7 +61,7 @@ is $called, 3, 'event was not emitted again';
$e->emit('test1');
is $called, 3, 'event was not emitted again';

# One time event
# One-time event
my $once;
$e->once(one_time => sub { $once++ });
is scalar @{$e->subscribers('one_time')}, 1, 'one subscriber';
Expand Down Expand Up @@ -89,7 +89,7 @@ $e->once(one_time => sub { $once = shift->has_subscribers('one_time') });
$e->emit('one_time');
ok !$once, 'no subscribers';

# Nested one time events
# Nested one-time events
$once = 0;
$e->once(
one_time => sub {
Expand Down

0 comments on commit c7b4d67

Please sign in to comment.