Permalink
Browse files

Add early-return optimisation in Text::Escape

Gets s26.html from 1m30 to 1m15.
  • Loading branch information...
1 parent 0e2cd07 commit 7d0e651f903fb6b0cd57f11e36a39529ff01aa6f @flussence flussence committed Aug 19, 2011
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/Text/Escape.pm
View
@@ -11,6 +11,8 @@ sub escape($str as Str, Str $how) is export {
}
sub escape_html(Str $str) returns Str is export {
+ return $str unless $str ~~ /<[&<>"']>/;
+
$str.subst(q{&}, q{&amp;}, :g)\
.subst(q{<}, q{&lt;}, :g)\
.subst(q{>}, q{&gt;}, :g)\
@@ -19,6 +21,8 @@ sub escape_html(Str $str) returns Str is export {
}
sub escape_uri(Str $str) returns Str is export {
+ return $str unless $str ~~ /<-[a..z A..Z 0..9 \-_.!~*'()]>/;
+
my Str $allowed = 'abcdefghijklmnopqrstuvwxyz'
~ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
~ '0123456789'

0 comments on commit 7d0e651

Please sign in to comment.