Permalink
Browse files

small optimizations

  • Loading branch information...
1 parent 1371e13 commit 701245a46dd19f0c8cfb5a61dc3df3e890337a52 @kraih committed Apr 3, 2012
Showing with 8 additions and 20 deletions.
  1. +2 −2 lib/Mojo/UserAgent/Transactor.pm
  2. +4 −16 lib/Mojo/Util.pm
  3. +2 −2 lib/Mojolicious/Routes/Pattern.pm
@@ -66,7 +66,7 @@ sub form {
# Multipart
$headers->content_type('multipart/form-data') if $multipart;
if (($headers->content_type || '') eq 'multipart/form-data') {
- my $parts = $self->_multipart($params->to_hash, $encoding);
+ my $parts = $self->_multipart($encoding, $params->to_hash);
$req->content(
Mojo::Content::MultiPart->new(headers => $headers, parts => $parts));
}
@@ -198,7 +198,7 @@ sub websocket {
}
sub _multipart {
- my ($self, $form, $encoding) = @_;
+ my ($self, $encoding, $form) = @_;
# Parts
my @parts;
View
@@ -284,6 +284,9 @@ my %REVERSE_ENTITIES = reverse %ENTITIES;
# "apos"
$ENTITIES{apos} = 39;
+# Entities regex for html_unescape
+my $ENTITIES_RE = qr/&(?:\#((?:\d{1,7}|x[0-9A-Fa-f]{1,6}))|([A-Za-z]{1,8}));/;
+
# Encode cache
my %ENCODE;
@@ -403,22 +406,7 @@ sub html_escape {
# Just relax and it'll come, son."
sub html_unescape {
my $string = shift;
- $string =~ s/
- &
- (?:
- \#
- (
- (?:
- \d{1,7} # Number
- |
- x[0-9A-Fa-f]{1,6} # Hex
- )
- )
- |
- ([A-Za-z]{1,8}) # Name
- )
- ;
- /_unescape($1, $2)/gex;
+ $string =~ s/$ENTITIES_RE/_unescape($1, $2)/ge;
return $string;
}
@@ -111,15 +111,15 @@ sub shape_match {
sub _compile {
my $self = shift;
- # Compile format regular expression
+ # Compile format regex
my $reqs = $self->reqs;
if (!exists $reqs->{format} || $reqs->{format}) {
my $format =
defined $reqs->{format} ? _compile_req($reqs->{format}) : '([^/]+)';
$self->format(qr#\.$format$#);
}
- # Compile tree to regular expression
+ # Compile tree to regex
my $block = '';
my $regex = '';
my $optional = 1;

0 comments on commit 701245a

Please sign in to comment.