diff options
author | David Mitchell <davem@iabyn.com> | 2017-07-11 13:43:26 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2017-07-27 11:30:23 +0100 |
commit | 7be75ccf16313d987eb5a6e9ff6aec9fea4ef3d4 (patch) | |
tree | ccbcd506c330c9798f660a9506c99d27f9b72c12 /t/perf | |
parent | 748f2c65599942147442f443949449a965f6d608 (diff) | |
download | perl-7be75ccf16313d987eb5a6e9ff6aec9fea4ef3d4.tar.gz |
optimise @array in boolean context
It's quicker to return (and to test for) &PL_sv_zero or &PL_sv_yes,
than setting a targ to an integer value or, in the vase of padav,
creating a mortal sv and setting it to an integer value.
In fact for padav, even in the scalar but non-boolean case, return
&PL_sv_zero if the value is zero rather than creating and setting a mortal.
Diffstat (limited to 't/perf')
-rw-r--r-- | t/perf/benchmarks | 40 | ||||
-rw-r--r-- | t/perf/optree.t | 10 |
2 files changed, 47 insertions, 3 deletions
diff --git a/t/perf/benchmarks b/t/perf/benchmarks index 76d0d74bc9..71afdfebd0 100644 --- a/t/perf/benchmarks +++ b/t/perf/benchmarks @@ -218,6 +218,46 @@ code => '($r||0)->[0][0][0]', }, + 'expr::array::lex_bool_empty' => { + desc => 'empty lexical array in boolean context', + setup => 'my @a;', + code => '!@a', + }, + 'expr::array::lex_bool_full' => { + desc => 'non-empty lexical array in boolean context', + setup => 'my @a = 1..10;', + code => '!@a', + }, + 'expr::array::lex_scalar_empty' => { + desc => 'empty lexical array in scalar context', + setup => 'my (@a, $i);', + code => '$i = @a', + }, + 'expr::array::lex_scalar_full' => { + desc => 'non-empty lexical array in scalar context', + setup => 'my @a = 1..10; my $i', + code => '$i = @a', + }, + 'expr::array::pkg_bool_empty' => { + desc => 'empty lexical array in boolean context', + setup => 'our @a;', + code => '!@a', + }, + 'expr::array::pkg_bool_full' => { + desc => 'non-empty lexical array in boolean context', + setup => 'our @a = 1..10;', + code => '!@a', + }, + 'expr::array::pkg_scalar_empty' => { + desc => 'empty lexical array in scalar context', + setup => 'our @a; my $i;', + code => '$i = @a', + }, + 'expr::array::pkg_scalar_full' => { + desc => 'non-empty lexical array in scalar context', + setup => 'our @a = 1..10; my $i', + code => '$i = @a', + }, 'expr::arrayhash::lex_3var' => { desc => 'lexical $h{$k1}[$i]{$k2}', diff --git a/t/perf/optree.t b/t/perf/optree.t index 04a4963eec..d74d52114a 100644 --- a/t/perf/optree.t +++ b/t/perf/optree.t @@ -13,7 +13,7 @@ BEGIN { @INC = '../lib'; } -plan 854; +plan 1490; use v5.10; # state use B qw(svref_2object @@ -208,8 +208,12 @@ is svref_2object(sub { "@_" })->ROOT->first->last->name, 'join', for my $ops ( # op code op path flag maybe flag + [ 'rv2av', '@pkg', [], OPpTRUEBOOL, 0, ], + [ 'rv2av', 'scalar(@pkg)', [0], OPpTRUEBOOL, 0, ], [ 'rv2hv', '%pkg', [], OPpTRUEBOOL, OPpMAYBE_TRUEBOOL ], [ 'rv2hv', 'scalar(%pkg)', [0], OPpTRUEBOOL, OPpMAYBE_TRUEBOOL ], + [ 'padav', '@lex', [], OPpTRUEBOOL, 0, ], + [ 'padav', 'scalar @lex', [0], OPpTRUEBOOL, 0, ], [ 'padhv', '%lex', [], OPpTRUEBOOL, OPpMAYBE_TRUEBOOL ], [ 'padhv', 'scalar(%lex)', [0], OPpTRUEBOOL, OPpMAYBE_TRUEBOOL ], [ 'ref', 'ref($x)', [], OPpTRUEBOOL, OPpMAYBE_TRUEBOOL ], @@ -368,8 +372,8 @@ for my $ops ( my $sub; { - our (%pkg); - my (%lex, $p, $q, $r, $x, $y); + our (@pkg, %pkg); + my (@lex, %lex, $p, $q, $r, $x, $y); no warnings 'void'; $sub = eval "sub { $code }" |