summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2017-01-06 14:59:54 +0000
committerDavid Mitchell <davem@iabyn.com>2017-06-05 16:16:50 +0100
commitba75e9a42bd919d317a4f5deb1e487c13586929d (patch)
tree1d737958be6befd3dedae0aeec0ac233a1c39801 /lib
parent520b6fb6871d18601e1bb968982f92f68ad523f5 (diff)
downloadperl-ba75e9a42bd919d317a4f5deb1e487c13586929d.tar.gz
make OP_REF support boolean context
RT #78288 When ref() is used in a boolean context, it's not necessary to return the name of the package which an object is blessed into; instead a simple truth value can be returned, which is faster. Note that it has to cope with the subtlety of an object blessed into the class "0", which should return false. Porting/bench.pl shows for the expression !ref($r), approximately: unchanged for a non-reference $r doubling of speed for a reference $r tripling of speed for a blessed reference $r This commit builds on the mechanism already used to set the OPpTRUEBOOL and OPpMAYBE_TRUEBOOL flags on padhv and rv2hv ops when used in boolean context.
Diffstat (limited to 'lib')
-rw-r--r--lib/B/Op_private.pm6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/B/Op_private.pm b/lib/B/Op_private.pm
index bb51b327f0..09931571f1 100644
--- a/lib/B/Op_private.pm
+++ b/lib/B/Op_private.pm
@@ -137,7 +137,7 @@ $bits{$_}{7} = 'OPpLVAL_INTRO' for qw(aelem aslice cond_expr delete enteriter en
$bits{$_}{2} = 'OPpLVREF_ELEM' for qw(lvref refassign);
$bits{$_}{3} = 'OPpLVREF_ITER' for qw(lvref refassign);
$bits{$_}{3} = 'OPpMAYBE_LVSUB' for qw(aassign aelem akeys aslice av2arylen avhvswitch helem hslice keys kvaslice kvhslice multideref padav padhv pos rv2av rv2gv rv2hv substr vec);
-$bits{$_}{4} = 'OPpMAYBE_TRUEBOOL' for qw(padhv rv2hv);
+$bits{$_}{4} = 'OPpMAYBE_TRUEBOOL' for qw(padhv ref rv2hv);
$bits{$_}{7} = 'OPpOFFBYONE' for qw(caller runcv wantarray);
$bits{$_}{5} = 'OPpOPEN_IN_CRLF' for qw(backtick open);
$bits{$_}{4} = 'OPpOPEN_IN_RAW' for qw(backtick open);
@@ -156,7 +156,7 @@ $bits{$_}{6} = 'OPpTRANS_GROWS' for qw(trans transr);
$bits{$_}{2} = 'OPpTRANS_IDENTICAL' for qw(trans transr);
$bits{$_}{3} = 'OPpTRANS_SQUASH' for qw(trans transr);
$bits{$_}{1} = 'OPpTRANS_TO_UTF' for qw(trans transr);
-$bits{$_}{5} = 'OPpTRUEBOOL' for qw(padhv rv2hv);
+$bits{$_}{5} = 'OPpTRUEBOOL' for qw(padhv ref rv2hv);
my @bf = (
{
@@ -807,7 +807,7 @@ our %ops_using = (
OPpLVAL_INTRO => [qw(aelem aslice cond_expr delete enteriter entersub gvsv helem hslice list lvavref lvref lvrefslice multideref padav padhv padrange padsv pushmark refassign rv2av rv2gv rv2hv rv2sv split)],
OPpLVREF_ELEM => [qw(lvref refassign)],
OPpMAYBE_LVSUB => [qw(aassign aelem akeys aslice av2arylen avhvswitch helem hslice keys kvaslice kvhslice multideref padav padhv pos rv2av rv2gv rv2hv substr vec)],
- OPpMAYBE_TRUEBOOL => [qw(padhv rv2hv)],
+ OPpMAYBE_TRUEBOOL => [qw(padhv ref rv2hv)],
OPpMULTIDEREF_DELETE => [qw(multideref)],
OPpOFFBYONE => [qw(caller runcv wantarray)],
OPpOPEN_IN_CRLF => [qw(backtick open)],