diff options
author | Yves Orton <demerphq@gmail.com> | 2023-03-28 14:38:01 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-04-05 15:22:55 +0800 |
commit | 564b0c90d4a5f7c04ed173bd9bac8d4241a9acb3 (patch) | |
tree | 3e59f4500374384f3dce6ea8572ded434a3a4dc0 /regen | |
parent | 113cefaa4a736b299757774019cd1ee97b7e2db9 (diff) | |
download | perl-564b0c90d4a5f7c04ed173bd9bac8d4241a9acb3.tar.gz |
regen/HeaderParser.pm - with multi-term expressions put least first
if we have defined(X) && (defined(Y) || defined(Z)) put the defined(X)
first because it has less operations in it.
Diffstat (limited to 'regen')
-rw-r--r-- | regen/HeaderParser.pm | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/regen/HeaderParser.pm b/regen/HeaderParser.pm index 7272a596c8..6869094874 100644 --- a/regen/HeaderParser.pm +++ b/regen/HeaderParser.pm @@ -196,6 +196,13 @@ sub _tokenize_expr { return \@tokens; } +sub _count_ops { + my ($self, $term)= @_; + my $count = 0; + $count++ while $term =~ m/(?: \|\| | \&\& | \? )/gx; + return $count; +} + # sort terms in an expression in a way that puts things # in a sensible order. Anything starting with PERL_IN_ # should be on the left in alphabetical order. Digits @@ -211,13 +218,15 @@ sub _sort_terms { lc($_) =~ s/[^a-zA-Z0-9]//gr, # 1: "_" stripped and caseless $_ =~ m/PERL_IN_/ ? 1 : 0, # 2: PERL_IN_ labeled define $_ =~ m/^\d/ ? 1 : 0, # 3: digit - $_ =~ m/DEBUGGING/ ? 1 : 0 # 4: DEBUGGING? + $_ =~ m/DEBUGGING/ ? 1 : 0, # 4: DEBUGGING? + $self->_count_ops($_), # 5: Number of ops (||, && and ternary) ] } @_; my %seen; #start-no-tidy @terms= map { $seen{ $_->[0] }++ ? () : $_->[0] } sort { + $a->[5] <=> $b->[5] || # least number of ops $b->[2] <=> $a->[2] || # PERL_IN before others $a->[3] <=> $b->[3] || # digits after others $a->[4] <=> $b->[4] || # DEBUGGING after all else |