This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make scalar(keys(%lexical)) less slow.
authorDavid Mitchell <davem@iabyn.com>
Sun, 23 Jul 2017 15:31:38 +0000 (16:31 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 27 Jul 2017 10:30:25 +0000 (11:30 +0100)
commit6f2dc9a6b978e866e22c46235932d018da8262ba
treeaaea4ac92d8aa676e597ecbf13aff28c3a58f65d
parent8dc9003ff3914e78971f561eaece965e9ceeb49e
make scalar(keys(%lexical)) less slow.

A recent commit in this branch made OP_PADHV / OP_RV2HV in void/scalar
context, followed by OP_KEYS, optimise away the OP_KEYS op and set the
OPpPADHV_ISKEYS or OPpRV2HV_ISKEYS flag on the OP_PADHV / OP_RV2HV op.

However, in scalar but non-boolean context with OP_PADHV, this actually
makes it slower, because the OP_KEYS op has a target, while the OP_PADHV
op doesn't, thus it has to create a new mortal each time to return the
integer value.

This commit fixes that by, in the case of scalar padhv, retaining the
OP_KEYS node (although still not keeping it in the execution path), then
at runtime using that op's otherwise unused target.

This only works on PERL_OP_PARENT builds (now the default) as the OP_KEYS
is the parent of the OP_PADHV, so would be hard to find at runtime
otherwise.

This commit also fixes pp_padhv/pp_rv2hv in void context - formerly it
was needlessly pushing a scalar-valued count like scalar context.
lib/B/Deparse.pm
op.c
pp_hot.c
t/perf/benchmarks