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 | |
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.
-rw-r--r-- | regcharclass.h | 4 | ||||
-rwxr-xr-x | regen/regcharclass.pl | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/regcharclass.h b/regcharclass.h index 5b04492b0f..f7ca75843e 100644 --- a/regcharclass.h +++ b/regcharclass.h @@ -647,7 +647,7 @@ */ /*** GENERATED CODE ***/ #define is_PROBLEMATIC_LOCALE_FOLD_utf8(s) \ -( ( ( NATIVE_TO_LATIN1(((U8*)s)[0]) & 0x80 ) == 0x00 ) ? 1 \ +( ( NATIVE_TO_LATIN1(((U8*)s)[0]) <= 0x7F ) ? 1 \ : ( ( NATIVE_TO_LATIN1(((U8*)s)[0]) & 0xFE ) == 0xC2 ) ? \ 2 \ : ( 0xC4 == NATIVE_TO_LATIN1(((U8*)s)[0]) || 0xC7 == NATIVE_TO_LATIN1(((U8*)s)[0]) ) ?\ @@ -684,7 +684,7 @@ */ /*** GENERATED CODE ***/ #define is_PROBLEMATIC_LOCALE_FOLDEDS_START_utf8(s) \ -( ( ( NATIVE_TO_LATIN1(((U8*)s)[0]) & 0x80 ) == 0x00 ) ? 1 \ +( ( NATIVE_TO_LATIN1(((U8*)s)[0]) <= 0x7F ) ? 1 \ : ( ( NATIVE_TO_LATIN1(((U8*)s)[0]) & 0xFE ) == 0xC2 ) ? \ 2 \ : ( 0xC4 == NATIVE_TO_LATIN1(((U8*)s)[0]) || 0xC7 == NATIVE_TO_LATIN1(((U8*)s)[0]) ) ?\ 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 = ""; |