This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make OP_REF support boolean context
authorDavid Mitchell <davem@iabyn.com>
Fri, 6 Jan 2017 14:59:54 +0000 (14:59 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 5 Jun 2017 15:16:50 +0000 (16:16 +0100)
commitba75e9a42bd919d317a4f5deb1e487c13586929d
tree1d737958be6befd3dedae0aeec0ac233a1c39801
parent520b6fb6871d18601e1bb968982f92f68ad523f5
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.
lib/B/Op_private.pm
op.c
opcode.h
pp.c
regen/op_private
t/op/ref.t
t/perf/benchmarks
t/perf/optree.t