Skip to content

Commit 66154fd

Browse files
committed
Also implement the negated versions of the flagged operators; ne:u and !=:u
1 parent 3be1a54 commit 66154fd

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

lib/B/Op_private.pm

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

op.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17086,8 +17086,10 @@ Perl_apply_opflags(pTHX_ U32 opcode, char *flagstr)
1708617086

1708717087
for(char flag; (flag = *flagstr); flagstr++) {
1708817088
switch(opcode_base) {
17089-
case OP_SEQ:
17090-
case OP_EQ:
17089+
case OP_SEQ: /* eq */
17090+
case OP_SNE: /* ne */
17091+
case OP_EQ: /* == */
17092+
case OP_NE: /* != */
1709117093
switch(flag) {
1709217094
case 'u':
1709317095
priv |= OPpEQ_UNDEF;

opcode.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,15 @@ PP(pp_ne)
22212221
SV *right = PL_stack_sp[0];
22222222
SV *left = PL_stack_sp[-1];
22232223

2224+
if(UNLIKELY(PL_op->op_private & OPpEQ_UNDEF)) {
2225+
bool lundef = !SvOK(left), rundef = !SvOK(right);
2226+
2227+
if(lundef || rundef) {
2228+
rpp_replace_2_IMM_NN(boolSV(!(lundef && rundef)));
2229+
return NORMAL;
2230+
}
2231+
}
2232+
22242233
U32 flags_and = SvFLAGS(left) & SvFLAGS(right);
22252234
U32 flags_or = SvFLAGS(left) | SvFLAGS(right);
22262235

@@ -2404,6 +2413,15 @@ PP(pp_sne)
24042413
SV *right = PL_stack_sp[0];
24052414
SV *left = PL_stack_sp[-1];
24062415

2416+
if(UNLIKELY(PL_op->op_private & OPpEQ_UNDEF)) {
2417+
bool lundef = !SvOK(left), rundef = !SvOK(right);
2418+
2419+
if(lundef || rundef) {
2420+
rpp_replace_2_IMM_NN(boolSV(!(lundef && rundef)));
2421+
return NORMAL;
2422+
}
2423+
}
2424+
24072425
rpp_replace_2_IMM_NN(boolSV(!sv_eq_flags(left, right, 0)));
24082426
return NORMAL;
24092427
}

regen/op_private

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ addbits('emptyavhv',
922922

923923
addbits($_,
924924
7 => qw(OPpEQ_UNDEF UNDEF),
925-
) for qw( eq seq );
925+
) for qw( eq ne seq sne );
926926

927927
addbits('argdefelem',
928928
7 => qw(OPpARG_IF_UNDEF IF_UNDEF),

t/op/equ.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ ok(not(123 ==:u 456), '==:u on different values');
6060
is($warnings, 0, 'no warnings were produced by use of undef');
6161
}
6262

63+
foreach (["abc", "abc"], ["abc", "def"], ["", undef], [undef, undef]) {
64+
my ($left, $right) = @$_;
65+
is(not($left ne:u $right), ($left eq:u $right), 'ne:u is a synonym for not(eq:u)');
66+
}
67+
6368
# ==:u treats undef as distinct, equal to itself, with no warnings
6469
{
6570
my $warnings = 0;
@@ -71,6 +76,11 @@ ok(not(123 ==:u 456), '==:u on different values');
7176
is($warnings, 0, 'no warnings were produced by use of undef');
7277
}
7378

79+
foreach ([123, 123], [123, 456], [0, undef], [undef, undef]) {
80+
my ($left, $right) = @$_;
81+
is(not($left !=:u $right), ($left ==:u $right), '!=:u is a synonym for not(==:u)');
82+
}
83+
7484
# performs GETMAGIC
7585
{
7686
"abc" =~ m/(\d+)/;

0 commit comments

Comments
 (0)