summaryrefslogtreecommitdiff
path: root/regen
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-11-22 15:45:05 -0700
committerKarl Williamson <khw@cpan.org>2020-11-22 16:01:08 -0700
commit6d2bbfb061d543d195ee99daf85841e44ece16ba (patch)
treec95737c1ef589d5f0093745c82bc7b6bfed9d2c7 /regen
parentef0a8475fdfef2bfeb82df0df1e8cc211790721e (diff)
downloadperl-6d2bbfb061d543d195ee99daf85841e44ece16ba.tar.gz
regcharclass.h: Simplify some expressions
The regen script was improperyly collapsing two-element ranges into two separate elements, which caused extraneous code to be generated.
Diffstat (limited to 'regen')
-rwxr-xr-xregen/regcharclass.pl17
1 files changed, 9 insertions, 8 deletions
diff --git a/regen/regcharclass.pl b/regen/regcharclass.pl
index 56fa7dd34e..d0d80d86d0 100755
--- a/regen/regcharclass.pl
+++ b/regen/regcharclass.pl
@@ -1049,25 +1049,26 @@ sub _cond_as_str {
my $is_cp_ret = $opts_ref->{ret_type} eq "cp";
return "( $test )" if !defined $cond;
- # rangify the list.
+ # rangify the list. As we encounter a new value, it is placed in a new
+ # subarray by itself. If the next value is adjacent to it, the end point
+ # of the subarray is merely incremented; and so on. When the next value
+ # that isn't adjacent to the previous one is encountered, Update() is
+ # called to hoist any single-element subarray to be a scalar.
my @ranges;
my $Update= sub {
# We skip this if there are optimizations that
# we can apply (below) to the individual ranges
if ( ($is_cp_ret || $combine) && @ranges && ref $ranges[-1]) {
- if ( $ranges[-1][0] == $ranges[-1][1] ) {
- $ranges[-1]= $ranges[-1][0];
- } elsif ( $ranges[-1][0] + 1 == $ranges[-1][1] ) {
- $ranges[-1]= $ranges[-1][0];
- push @ranges, $ranges[-1] + 1;
- }
+ $ranges[-1] = $ranges[-1][0] if $ranges[-1][0] == $ranges[-1][1];
}
};
for my $condition ( @$cond ) {
if ( !@ranges || $condition != $ranges[-1][1] + 1 ) {
+ # Not adjacent to the existing range. Remove that from being a
+ # range if only a single value;
$Update->();
push @ranges, [ $condition, $condition ];
- } else {
+ } else { # Adjacent to the existing range; add to the range
$ranges[-1][1]++;
}
}