Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 23, 2012
1 parent 356c647 commit 4721ab9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/Mojo/Util.pm
Expand Up @@ -2369,8 +2369,8 @@ my %ENTITIES = (
);

# Reverse entities for html_escape
my %REVERSE_ENTITIES;
$REVERSE_ENTITIES{$ENTITIES{$_}} //= $_ for reverse sort keys %ENTITIES;
my %REVERSE;
$REVERSE{$ENTITIES{$_}} //= $_ for reverse sort keys %ENTITIES;

# "apos"
$ENTITIES{'apos;'} = "\x{0027}";
Expand Down Expand Up @@ -2476,11 +2476,8 @@ sub html_escape {

my $escaped = '';
for my $i (0 .. (length($string) - 1)) {

# Escape entities
my $char = substr $string, $i, 1;
if (my $named = $REVERSE_ENTITIES{$char}) { $char = "&$named" }
$escaped .= $char;
$escaped .= exists $REVERSE{$char} ? "&$REVERSE{$char}" : $char;
}

return $escaped;
Expand Down

0 comments on commit 4721ab9

Please sign in to comment.