summaryrefslogtreecommitdiff
path: root/t/perf
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2017-01-04 23:50:14 +0000
committerDavid Mitchell <davem@iabyn.com>2017-01-06 16:28:27 +0000
commit9d692a7f83cf8fe36c59aaa07bca533887350e9b (patch)
treeb1aef56bc9c2aaa3447cafca50bf5cae4f7bee3e /t/perf
parent2ee1faad3521a3f4af605ff9c9242b912259f946 (diff)
downloadperl-9d692a7f83cf8fe36c59aaa07bca533887350e9b.tar.gz
add xor, grep, flip, flop to boolean cxt detection
The code that detects whether certain ops (currently just PADHV and RV2HV) are called in boolean context only recognises a few ops as providing boolean context: NOT, OR, DOR, AND, COND_EXPR. This commit expands this by adding GREPWHILE, FLIP, FLOP, XOR too (in the case of XOR it only applies to the RHS arg - the LHS is not simple to detect). This means that in something like @AofH_nonempty = grep %$_, @AofH the test for each hash being non-empty will now be done in boolean rather than full scalar context, so may be faster. Similarly (although less excitingly) these hash key counts are also boolean now: %hash .. $other; $other .. %hash; $other xor %hash; (I basically did a grep for 'SvTRUE' in pp*.c to see what other ops might be imposing boolean context.) Since this has been added to the general boolean context detection mechanism, it will also apply for any future ops with are 'booleanised'.
Diffstat (limited to 't/perf')
-rw-r--r--t/perf/optree.t34
1 files changed, 33 insertions, 1 deletions
diff --git a/t/perf/optree.t b/t/perf/optree.t
index 189cee081c..4aebb9eebe 100644
--- a/t/perf/optree.t
+++ b/t/perf/optree.t
@@ -13,7 +13,7 @@ BEGIN {
@INC = '../lib';
}
-plan 543;
+plan 711;
use v5.10; # state
use B qw(svref_2object
@@ -312,6 +312,38 @@ for my $ops (
[ [1,9,1], [0,0,0,1], 'if ($x && %s) {$x} else {$y}' ],
[ [1,9,2], [0,0,0,1], 'unless ($x && %s) {$x}' ],
+ # INNER XOR LHS
+
+ # LHS of XOR is currently too hard to detect as
+ # being in boolean context
+
+ # INNER XOR RHS
+
+ [ [1,1,1], [1], '($x xor %s)' ],
+ [ [1,1,1], [0,1], '!($x xor %s)' ],
+ [ [1,1,1], [0,1,1], '$y || ($x xor %s)' ],
+ [ [1,9,1], [0,0,1], 'if ($x xor %s) {$x}' ],
+ [ [1,9,1], [0,0,1], 'if ($x xor %s) {$x} else {$y}' ],
+ [ [1,9,1], [0,0,1], 'unless ($x xor %s) {$x}' ],
+
+ # GREP
+
+ [ [1,1,1], [0,1,0], 'grep %s,1,2' ],
+ [ [1,1,1], [0,1,0,0], 'grep !%s,1,2' ],
+ [ [1,1,1], [0,1,0,0,1],'grep $y || %s,1,2' ],
+
+ # FLIP
+
+ [ [1,1,1], [0,0,0,0], '%s..$x' ],
+ [ [1,1,1], [0,0,0,0,0], '!%s..$x' ],
+ [ [1,1,1], [0,0,0,0,0,1], '($y || %s)..$x' ],
+
+ # FLOP
+
+ [ [1,1,1], [0,0,0,1], '$x..%s' ],
+ [ [1,1,1], [0,0,0,1,0], '$x..!%s' ],
+ [ [1,1,1], [0,0,0,1,0,1], '$x..($y || %s)' ],
+
) {
my ($expects, $op_path, $code_fmt) = @$test;