diff options
author | Karl Williamson <khw@cpan.org> | 2014-05-03 15:38:27 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-05-30 16:11:28 -0600 |
commit | 726137b54cce68fcc6b29154c8dd4b58a2b1e4d9 (patch) | |
tree | b8a073959d46ac4f44e9760060445147c3e2b52c /regen/regcharclass.pl | |
parent | b94eb3d40b0d2ecf5510a08ef19e565105f6f7fe (diff) | |
download | perl-726137b54cce68fcc6b29154c8dd4b58a2b1e4d9.tar.gz |
regen/regcharclass.pl: Improve the generated code
This is a small improvement when a consecutive group of U8 code points
begins at 0 or ends at 255. These end points are physically impossible
of being exceeded, so there is no need to test for that end of the
range. In several places this causes a mask operation to not be
generated.
Diffstat (limited to 'regen/regcharclass.pl')
-rwxr-xr-x | regen/regcharclass.pl | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/regen/regcharclass.pl b/regen/regcharclass.pl index 002cd0f6a9..1f780a48f5 100755 --- a/regen/regcharclass.pl +++ b/regen/regcharclass.pl @@ -1097,6 +1097,21 @@ sub _cond_as_str { $ranges[$i] = # Trivial case: single element range sprintf "$self->{val_fmt} == $test", $ranges[$i]->[0]; } + elsif ($ranges[$i]->[0] == 0) { + # If the range matches all 256 possible bytes, it is trivially + # true. + return 1 if $ranges[0]->[1] == 0xFF; # @ranges must be 1 in + # this case + $ranges[$i] = sprintf "( $test <= $self->{val_fmt} )", + $ranges[$i]->[1]; + } + elsif ($ranges[$i]->[1] == 255) { + + # Similarly the max possible is 255, so can omit an upper bound + # test if the calculated max is the max possible one. + $ranges[$i] = sprintf "( $test >= $self->{val_fmt} )", + $ranges[0]->[0]; + } else { my $output = ""; |