Skip to content

Commit 5522901

Browse files
committed
Additionally implement a numerical version, ==:u
1 parent 6e28748 commit 5522901

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

lib/B/Op_private.pm

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

opcode.h

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

pp_hot.c

+9
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,15 @@ PP(pp_eq)
16811681
SV *right = PL_stack_sp[0];
16821682
SV *left = PL_stack_sp[-1];
16831683

1684+
if(UNLIKELY(PL_op->op_private & OPpEQ_UNDEF)) {
1685+
bool lundef = !SvOK(left), rundef = !SvOK(right);
1686+
1687+
if(lundef || rundef) {
1688+
rpp_replace_2_IMM_NN(boolSV(lundef && rundef));
1689+
return NORMAL;
1690+
}
1691+
}
1692+
16841693
U32 flags_and = SvFLAGS(left) & SvFLAGS(right);
16851694
U32 flags_or = SvFLAGS(left) | SvFLAGS(right);
16861695

regen/op_private

+2-2
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,9 @@ addbits('emptyavhv',
920920
# 4 OPpTARGET_MY
921921
);
922922

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

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

t/op/equ.t

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ BEGIN {
1010
}
1111

1212
### PPC0030-style `equ` operator
13+
# does not test the numerical version because there are still discussions
14+
# about its spelling; `===` is considered problematic.
1315

1416
# equ behaves like eq on defined strings
1517
ok("abc" equ "abc", 'equ on identical values');
@@ -42,6 +44,11 @@ ok("abc" eq:u "abc", 'eq:u on identical values');
4244
ok("" eq:u "", 'eq:u on empty/empty');
4345
ok(not("abc" eq:u "def"), 'eq:u on different values');
4446

47+
# ==:u behaves like == on defined numbers
48+
ok(123 ==:u 123, '==:u on identical values');
49+
ok(0 ==:u 0, '==:u on zero/zero');
50+
ok(not(123 ==:u 456), '==:u on different values');
51+
4552
# eq:u treats undef as distinct, equal to itself, with no warnings
4653
{
4754
my $warnings = 0;
@@ -53,6 +60,17 @@ ok(not("abc" eq:u "def"), 'eq:u on different values');
5360
is($warnings, 0, 'no warnings were produced by use of undef');
5461
}
5562

63+
# ==:u treats undef as distinct, equal to itself, with no warnings
64+
{
65+
my $warnings = 0;
66+
local $SIG{__WARN__} = sub { $warnings++; };
67+
68+
ok(undef ==:u undef, 'eq:u on undef/undef');
69+
ok(not(undef ==:u 0), 'eq:u on undef/zero');
70+
71+
is($warnings, 0, 'no warnings were produced by use of undef');
72+
}
73+
5674
# performs GETMAGIC
5775
{
5876
"abc" =~ m/(\d+)/;

0 commit comments

Comments
 (0)