Skip to content

Commit 3d75a04

Browse files
committed
regen/embed.pl: Use tr/// to save operations
I, and previous authors had forgotten that tr returns a count of matching characters, so can tell you if more than one character in the input string matches; as well as if none do.
1 parent 2cbcb30 commit 3d75a04

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

regen/embed.pl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ($$)
5252
if ($flags =~ /[ps]/) {
5353

5454
# An all uppercase macro name gets an uppercase prefix.
55-
return ($flags =~ /m/ && $flags =~ /p/ && $func !~ /[[:lower:]]/)
55+
return (($flags =~ tr/mp// > 1) && $func !~ /[[:lower:]]/)
5656
? "PERL_$func"
5757
: "Perl_$func";
5858
}
@@ -135,7 +135,7 @@ sub generate_proto_h {
135135
my $binarycompat = ( $flags =~ /b/ );
136136
my $has_mflag = ( $flags =~ /m/ );
137137
my $is_malloc = ( $flags =~ /a/ );
138-
my $can_ignore = ( $flags !~ /R/ ) && ( $flags !~ /P/ ) && !$is_malloc;
138+
my $can_ignore = ($flags =~ tr/RP// == 0) && !$is_malloc;
139139
my @asserts;
140140
my $func;
141141

@@ -144,7 +144,7 @@ sub generate_proto_h {
144144
}
145145

146146
die_at_end "$plain_func: S and p flags are mutually exclusive"
147-
if $flags =~ /S/ && $flags =~ /p/;
147+
if $flags =~ tr/Sp// > 1;
148148
if ($has_mflag) {
149149
if ($flags =~ /S/) {
150150
die_at_end "$plain_func: m and S flags are mutually exclusive";
@@ -229,7 +229,7 @@ sub generate_proto_h {
229229
die_at_end "For '$plain_func', b flag without M flag requires D flag"
230230
if $flags =~ /b/ && $flags !~ /M/ && $flags !~ /D/;
231231
die_at_end "For '$plain_func', I and i flags are mutually exclusive"
232-
if $flags =~ /I/ && $flags =~ /i/;
232+
if $flags =~ tr/Ii// > 1;
233233

234234
$ret = "";
235235
$ret .= "$retval\n";
@@ -545,7 +545,7 @@ sub embed_h {
545545
$ind .= " " x ($level-1) if $level>1;
546546
my $inner_ind= $ind ? " " : " ";
547547

548-
if ($flags =~ /m/ && $flags =~ /p/) {
548+
if ($flags =~ tr/mp// > 1) { # Has both m and p
549549

550550
# Yields
551551
# #define Perl_func func

0 commit comments

Comments
 (0)