Skip to content
Permalink
Browse files

improve Mojo::URL performance significantly

  • Loading branch information...
kraih committed Jul 29, 2017
1 parent 7f48299 commit a7cdf6fb2c60c28ac4ab9ffad0e528bb23b0f7b8
Showing with 17 additions and 6 deletions.
  1. +2 −1 Changes
  2. +15 −5 lib/Mojo/Util.pm
@@ -1,6 +1,7 @@

7.38 2017-07-26
7.38 2017-07-29
- Added extra attribute to Mojolicious::Static. (jabberwok)
- Improve Mojo::URL performance significantly.

7.37 2017-07-21
- Added slugify method to Mojo::ByteStream. (Grinnz)
@@ -55,8 +55,8 @@ my $EXPIRES_RE = qr/(\w+\W+\d+\W+\w+\W+\d+\W+\d+:\d+:\d+\W*\w+)/;
# HTML entities
my $ENTITY_RE = qr/&(?:\#((?:[0-9]{1,7}|x[0-9a-fA-F]{1,6}));|(\w+[;=]?))/;

# Encoding cache
my %CACHE;
# Encoding and pattern cache
my (%ENCODING, %PATTERN);

our @EXPORT_OK = (
qw(b64_decode b64_encode camelize class_to_file class_to_path decamelize),
@@ -316,8 +316,18 @@ sub unquote {

sub url_escape {
my ($str, $pattern) = @_;
if ($pattern) { $str =~ s/([$pattern])/sprintf '%%%02X', ord $1/ge }
else { $str =~ s/([^A-Za-z0-9\-._~])/sprintf '%%%02X', ord $1/ge }

if ($pattern) {
unless (exists $PATTERN{$pattern}) {
(my $quoted = $pattern) =~ s!([/\$\[])!\\$1!g;

This comment has been minimized.

Copy link
@truist

truist Oct 12, 2017

@kraih just FYI that something about this change broke existing code of mine; I had been using:

return Mojo::Util::url_escape(@_, '^A-Za-z0-9\-._~\/\?\=');

...but after this change, I had to un-escape the last three characters to avoid errors about unmatched [ and undefined objects:

return Mojo::Util::url_escape(@_, '^A-Za-z0-9\-._~/?=');

This comment has been minimized.

Copy link
@truist
$PATTERN{$pattern}
= eval "sub { \$_[0] =~ s/([$quoted])/sprintf '%%%02X', ord \$1/ge }"
or croak $@;
}
$PATTERN{$pattern}->($str);
}
else { $str =~ s/([^A-Za-z0-9\-._~])/sprintf '%%%02X', ord $1/ge }

return $str;
}

@@ -361,7 +371,7 @@ sub _adapt {
}

sub _encoding {
$CACHE{$_[0]} //= find_encoding($_[0]) // croak "Unknown encoding '$_[0]'";
$ENCODING{$_[0]} //= find_encoding($_[0]) // croak "Unknown encoding '$_[0]'";
}

sub _entity {

0 comments on commit a7cdf6f

Please sign in to comment.
You can’t perform that action at this time.