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 /embed.h | |
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 'embed.h')
-rw-r--r-- | embed.h | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -1171,6 +1171,7 @@ #define ck_delete(a) Perl_ck_delete(aTHX_ a) #define ck_each(a) Perl_ck_each(aTHX_ a) #define ck_eof(a) Perl_ck_eof(aTHX_ a) +#define ck_eq(a) Perl_ck_eq(aTHX_ a) #define ck_eval(a) Perl_ck_eval(aTHX_ a) #define ck_exec(a) Perl_ck_exec(aTHX_ a) #define ck_exists(a) Perl_ck_exists(aTHX_ a) |