Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed Sep 4, 2012
1 parent db45266 commit 47b1fac
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

3.38 2012-09-05
- Improved documentation.

3.37 2012-09-04
- Added finish method to Mojo::Message.
- Updated jQuery to version 1.8.1.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/ByteStream.pm
Expand Up @@ -275,7 +275,7 @@ Read all data into bytestream with L<Mojo::Util/"slurp">.
Write bytestream to file with L<Mojo::Util/"spurt">.
b('/home/sri/foo.html')->slurp->html_unescape->spurt('/home/sri/bar.html');
b('/home/sri/foo.txt')->slurp->squish->spurt('/home/sri/bar.txt');
=head2 C<split>
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Content.pm
Expand Up @@ -8,6 +8,8 @@ has [qw(auto_relax relaxed skip_body)];
has headers => sub { Mojo::Headers->new };
has max_leftover_size => sub { $ENV{MOJO_MAX_LEFTOVER_SIZE} || 262144 };

my $CHUNK_RE = qr/^((?:\x0d?\x0a)?([[:xdigit:]]+).*\x0d?\x0a)/;

sub body_contains {
croak 'Method "body_contains" not implemented by subclass';
}
Expand Down Expand Up @@ -242,7 +244,7 @@ sub _parse_chunked {
if ($self->{chunk_state} // '') eq 'trailing_headers';

# New chunk (ignore the chunk extension)
while ($self->{pre_buffer} =~ /^((?:\x0d?\x0a)?([\da-fA-F]+).*\x0d?\x0a)/) {
while ($self->{pre_buffer} =~ $CHUNK_RE) {
my $header = $1;
my $len = hex $2;

Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -base;

has 'tree';

my $ESCAPE_RE = qr/\\[^0-9a-fA-F]|\\[0-9a-fA-F]{1,6}/;
my $ESCAPE_RE = qr/\\[^[:xdigit:]]|\\[[:xdigit:]]{1,6}/;
my $ATTR_RE = qr/
\[
((?:$ESCAPE_RE|[\w\-])+) # Key
Expand Down Expand Up @@ -365,7 +365,7 @@ sub _unescape {
$value =~ s/\\\n//g;

# Unescape Unicode characters
$value =~ s/\\([0-9a-fA-F]{1,6})\s?/pack('U', hex $1)/ge;
$value =~ s/\\([[:xdigit:]]{1,6})\s?/pack('U', hex $1)/ge;

# Remove backslash
$value =~ s/\\//g;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -156,7 +156,7 @@ sub _decode_string {
my $pos = pos;

# Extract string with escaped characters
m#\G(((?:[^\x00-\x1F\\"]|\\(?:["\\/bfnrt]|u[A-Fa-f0-9]{4})){0,32766})*)#gc;
m#\G(((?:[^\x00-\x1F\\"]|\\(?:["\\/bfnrt]|u[[:xdigit:]]{4})){0,32766})*)#gc;
my $str = $1;

# Missing quote
Expand Down
13 changes: 5 additions & 8 deletions lib/Mojo/Util.pm
Expand Up @@ -103,8 +103,8 @@ sub get_line {
return $line;
}
sub hmac_md5_sum { _hmac(0, @_) }
sub hmac_sha1_sum { _hmac(1, @_) }
sub hmac_md5_sum { _hmac(\&md5, @_) }
sub hmac_sha1_sum { _hmac(\&sha1, @_) }
sub html_escape {
my ($string, $pattern) = @_;
Expand All @@ -117,7 +117,7 @@ sub html_escape {
sub html_unescape {
my $string = shift;
$string
=~ s/&(?:\#((?:\d{1,7}|x[0-9A-Fa-f]{1,6}));|(\w+;?))/_decode($1, $2)/ge;
=~ s/&(?:\#((?:\d{1,7}|x[[:xdigit:]]{1,6}));|(\w+;?))/_decode($1, $2)/ge;
return $string;
}

Expand Down Expand Up @@ -306,7 +306,7 @@ sub url_escape {
sub url_unescape {
my $string = shift;
return $string if index($string, '%') == -1;
$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge;
$string =~ s/%([[:xdigit:]]{2})/chr(hex($1))/ge;
return $string;
}

Expand Down Expand Up @@ -357,10 +357,7 @@ sub _encode {
}

sub _hmac {
my ($sha, $string, $secret) = @_;

# Hash function
my $hash = $sha ? sub { sha1(@_) } : sub { md5(@_) };
my ($hash, $string, $secret) = @_;

# Secret
$secret = $secret ? "$secret" : 'Very insecure!';
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.37';
our $VERSION = '3.38';

sub AUTOLOAD {
my $self = shift;
Expand Down

0 comments on commit 47b1fac

Please sign in to comment.