diff options
author | Todd Rinaldo <toddr@cpan.org> | 2010-09-28 11:13:33 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2010-09-28 11:13:33 -0700 |
commit | 152eae845915a3a33260ad109ad3888c8894d666 (patch) | |
tree | 478e87d2c30dcfdde03d3d3cc4eb48f4b1d1429d /dist | |
parent | cffb36981555111f364a511fb5763f65ea748c0e (diff) | |
download | perl-152eae845915a3a33260ad109ad3888c8894d666.tar.gz |
[perl #76674] Locale::Maketext: speed and efficiency tweaks
Check string to compile for chars ~][ and return \"$string" if not found.
This is a 250% speed improvement on strings which don't require compile and only a
~2% hit if they did need compiling.
Remove \G since everything is being captured it has no value. This means we don't
have to worry about seting pos $string_to_compile = 0 to prevent the previous
regex from affecting this one. There is a negligible speed improvement removing
the \G
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Locale-Maketext/lib/Locale/Maketext.pm | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/dist/Locale-Maketext/lib/Locale/Maketext.pm b/dist/Locale-Maketext/lib/Locale/Maketext.pm index cbfcb14bc7..a685d6be53 100644 --- a/dist/Locale-Maketext/lib/Locale/Maketext.pm +++ b/dist/Locale-Maketext/lib/Locale/Maketext.pm @@ -489,6 +489,13 @@ sub _compile { # It returns either a coderef if there's brackety bits in this, or # otherwise a ref to a scalar. + my $string_to_compile = $_[1]; # There are taint issues using regex on @_ - perlbug 60378,27344 + + # The while() regex is more expensive than this check on strings that don't need a compile. + # this op causes a ~2% speed hit for strings that need compile and a 250% speed improvement + # on strings that don't need compiling. + return \"$string_to_compile" if($string_to_compile !~ m/[\[~\]]/ms); # return a string ref if chars [~] are not in the string + my $target = ref($_[0]) || $_[0]; my(@code); @@ -499,10 +506,9 @@ sub _compile { my $in_group = 0; # start out outside a group my($m, @params); # scratch - my $string_to_compile = $_[1]; # There are taint issues using regex on @_ - perlbug 60378,27344 while($string_to_compile =~ # Iterate over chunks. - m/\G( - [^\~\[\]]+ # non-~[] stuff + m/( + [^\~\[\]]+ # non-~[] stuff (Capture everything else here) | ~. # ~[, ~], ~~, ~other | |