diff options
author | David Mitchell <davem@iabyn.com> | 2017-07-14 17:29:43 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2017-07-27 11:30:23 +0100 |
commit | 7e8d786b02d3ef1f946a5ac354c2780774902e15 (patch) | |
tree | b69a07af62ca20710fe7794118b2c5e8500737e6 /regen/opcodes | |
parent | 12dc5f9406fbb8389be8b9f9406ad247ca07f210 (diff) | |
download | perl-7e8d786b02d3ef1f946a5ac354c2780774902e15.tar.gz |
optimise (index() == -1)
Unusually, index() and rindex() return -1 on failure.
So it's reasonably common to see code like
if (index(...) != -1) { ... }
and variants.
For such code, this commit optimises away to OP_EQ and OP_CONST,
and sets a couple of private flags on the index op instead, indicating:
OPpTRUEBOOL return a boolean which is a comparison of
what the return would have been, against -1
OPpINDEX_BOOLNEG negate the boolean result
Its also supports OPpTRUEBOOL in conjunction with the existing
OPpTARGET_MY flag, so for example in
$lexical = (index(...) == -1)
the padmy, sassign, eq and const ops are all optimised away.
Diffstat (limited to 'regen/opcodes')
-rw-r--r-- | regen/opcodes | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/regen/opcodes b/regen/opcodes index f1e439d0be..58d08c3f3c 100644 --- a/regen/opcodes +++ b/regen/opcodes @@ -144,10 +144,10 @@ le numeric le (<=) ck_cmp Iifs2 S S< i_le integer le (<=) ck_cmp ifs2 S S< ge numeric ge (>=) ck_cmp Iifs2 S S< i_ge integer ge (>=) ck_cmp ifs2 S S< -eq numeric eq (==) ck_null Iifs2 S S< -i_eq integer eq (==) ck_null ifs2 S S< -ne numeric ne (!=) ck_null Iifs2 S S< -i_ne integer ne (!=) ck_null ifs2 S S< +eq numeric eq (==) ck_eq Iifs2 S S< +i_eq integer eq (==) ck_eq ifs2 S S< +ne numeric ne (!=) ck_eq Iifs2 S S< +i_ne integer ne (!=) ck_eq ifs2 S S< ncmp numeric comparison (<=>) ck_null Iifst2 S S< i_ncmp integer comparison (<=>) ck_null ifst2 S S< |