Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed Nov 16, 2012
1 parent b91f4d4 commit 9210a0a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -161,27 +161,23 @@ sub _parse_multipart_boundary {
sub _parse_multipart_preamble {
my ($self, $boundary) = @_;

# Replace preamble with carriage return and line feed
my $pos = index $self->{multipart}, "--$boundary";
unless ($pos < 0) {
substr $self->{multipart}, 0, $pos, "\x0d\x0a";
# No boundary yet
return undef if (my $pos = index $self->{multipart}, "--$boundary") < 0;

# Parse boundary
return !!($self->{multi_state} = 'multipart_boundary');
}
# Replace preamble with carriage return and line feed
substr $self->{multipart}, 0, $pos, "\x0d\x0a";

# No boundary yet
return undef;
# Parse boundary
return !!($self->{multi_state} = 'multipart_boundary');
}

sub _read {
my ($self, $chunk) = @_;

# Parse
$self->{multipart} .= $chunk;
$self->{multi_state} ||= 'multipart_preamble';
my $boundary = $self->boundary;
until ($self->{multi_state} eq 'finished') {
until (($self->{multi_state} //= 'multipart_preamble') eq 'finished') {

# Preamble
if (($self->{multi_state} // '') eq 'multipart_preamble') {
Expand Down

0 comments on commit 9210a0a

Please sign in to comment.