This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Better optimise my/local @a = split()
authorDavid Mitchell <davem@iabyn.com>
Mon, 19 Sep 2016 11:35:13 +0000 (12:35 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 4 Oct 2016 10:18:40 +0000 (11:18 +0100)
commit692044df8403d4568b919fe9ad7e282e864ec85e
treecee2e122d90dc7fc942964679cfd808189e5c390
parent70027d69be2857dc45d5ff75021fc5f55d6295da
Better optimise my/local @a = split()

There are currently two optimisations for when the results of a split
are assigned to an array.

For the first,

    @array = split(...);

the aassign and padav/rv2av are optimised away, and pp_split() directly
assigns to the array attached to the split op (via op_pmtargetoff or
op_pmtargetgv).

For the second,

    my @array    = split(...);
    local @array = split(...);
    @{$expr}     = split(...);

The aassign is optimised away, but the padav/rv2av is kept as an additional
arg to split. pp_split itself then uses the first arg popped off the stack
as the array (This was introduced by FC with v5.21.4-409-gef7999f).

This commit moves these two:

    my @array    = split(...);
    local @array = split(...);

from the second case to the first case, by simply setting OPpLVAL_INTRO
on the OP_SPLIT, and making pp_split() do SAVECLEARSV() or save_ary()
as appropriate.

This makes my @a = split(...) a few percent faster.
ext/B/B/Concise.pm
lib/B/Deparse.pm
lib/B/Op_private.pm
op.c
opcode.h
pp.c
regen/op_private
t/op/split.t
t/perf/benchmarks
t/perf/opcount.t