Skip to content

Commit ac020e6

Browse files
committed
Also implement the negated versions of the flagged operators; ne:u and !=:u
1 parent 7aeda2d commit ac020e6

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

lib/B/Op_private.pm

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

op.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -16200,8 +16200,10 @@ Perl_apply_opflags(pTHX_ U32 opcode, char *flagstr)
1620016200

1620116201
for(char flag; (flag = *flagstr); flagstr++) {
1620216202
switch(opcode_base) {
16203-
case OP_SEQ:
16204-
case OP_EQ:
16203+
case OP_SEQ: /* eq */
16204+
case OP_SNE: /* ne */
16205+
case OP_EQ: /* == */
16206+
case OP_NE: /* != */
1620516207
switch(flag) {
1620616208
case 'u':
1620716209
priv |= OPpEQ_UNDEF;

opcode.h

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pp.c

+18
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,15 @@ PP(pp_ne)
22902290
SV *right = PL_stack_sp[0];
22912291
SV *left = PL_stack_sp[-1];
22922292

2293+
if(UNLIKELY(PL_op->op_private & OPpEQ_UNDEF)) {
2294+
bool lundef = !SvOK(left), rundef = !SvOK(right);
2295+
2296+
if(lundef || rundef) {
2297+
rpp_replace_2_IMM_NN(boolSV(!(lundef && rundef)));
2298+
return NORMAL;
2299+
}
2300+
}
2301+
22932302
U32 flags_and = SvFLAGS(left) & SvFLAGS(right);
22942303
U32 flags_or = SvFLAGS(left) | SvFLAGS(right);
22952304

@@ -2473,6 +2482,15 @@ PP(pp_sne)
24732482
SV *right = PL_stack_sp[0];
24742483
SV *left = PL_stack_sp[-1];
24752484

2485+
if(PL_op->op_private & OPpEQ_UNDEF) {
2486+
bool lundef = !SvOK(left), rundef = !SvOK(right);
2487+
2488+
if(lundef || rundef) {
2489+
rpp_replace_2_IMM_NN(boolSV(!(lundef && rundef)));
2490+
return NORMAL;
2491+
}
2492+
}
2493+
24762494
rpp_replace_2_IMM_NN(boolSV(!sv_eq_flags(left, right, 0)));
24772495
return NORMAL;
24782496
}

regen/op_private

+1-1
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

+10
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)