diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2022-12-10 15:45:10 +0000 |
---|---|---|
committer | Paul Evans <leonerd@leonerd.org.uk> | 2022-12-19 17:27:55 +0000 |
commit | abf1aa2b099b9613c2e6901d3f61eb8da735d934 (patch) | |
tree | bf21b4d273643874ea55af93ce951dd6d46f84bb /lib/B/Op_private.pm | |
parent | e53949d80e5b3c49f5b33071e988970b50cf8f66 (diff) | |
download | perl-abf1aa2b099b9613c2e6901d3f61eb8da735d934.tar.gz |
Define OP_HELEMEXISTSOR, a handy LOGOP shortcut for HELEM existence tests
This op is constructed using an OP_HELEM as the op_first and any scalar
expression as the op_other.
It is roughly equivalent to the following perl code:
exists $hv{$key} ? $hv{$key} : OTHER
except that the HV and the KEY expression are evaluated only once, and
only one hv_* function is invoked to both test and obtain the value. It
is therefore smaller and more efficient.
Likewise, adding the OPpHELEMEXISTSOR_DELETE flag turns it into the
equivalent of
exists $hv{$key} ? delete $hv{$key} : OTHER
Diffstat (limited to 'lib/B/Op_private.pm')
-rw-r--r-- | lib/B/Op_private.pm | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/B/Op_private.pm b/lib/B/Op_private.pm index 28ae8fc649..bf189a128b 100644 --- a/lib/B/Op_private.pm +++ b/lib/B/Op_private.pm @@ -384,6 +384,7 @@ $bits{grepwhile}{0} = $bf[0]; @{$bits{gt}}{1,0} = ($bf[1], $bf[1]); $bits{gv}{5} = 'OPpEARLY_CV'; @{$bits{helem}}{5,4,1,0} = ($bf[8], $bf[8], $bf[1], $bf[1]); +@{$bits{helemexistsor}}{7,0} = ('OPpHELEMEXISTSOR_DELETE', $bf[0]); $bits{hex}{0} = $bf[0]; @{$bits{i_add}}{1,0} = ($bf[1], $bf[1]); @{$bits{i_divide}}{1,0} = ($bf[1], $bf[1]); @@ -643,6 +644,7 @@ our %defines = ( OPpFT_AFTER_t => 16, OPpFT_STACKED => 4, OPpFT_STACKING => 8, + OPpHELEMEXISTSOR_DELETE => 128, OPpHINT_STRICT_REFS => 2, OPpHUSH_VMSISH => 32, OPpINDEX_BOOLNEG => 64, @@ -753,6 +755,7 @@ our %labels = ( OPpFT_AFTER_t => 'FTAFTERt', OPpFT_STACKED => 'FTSTACKED', OPpFT_STACKING => 'FTSTACKING', + OPpHELEMEXISTSOR_DELETE => 'DELETE', OPpHINT_STRICT_REFS => 'STRICT', OPpHUSH_VMSISH => 'HUSH', OPpINDEX_BOOLNEG => 'NEG', @@ -834,6 +837,7 @@ our %ops_using = ( OPpFLIP_LINENUM => [qw(flip flop)], OPpFT_ACCESS => [qw(fteexec fteread ftewrite ftrexec ftrread ftrwrite)], OPpFT_AFTER_t => [qw(ftatime ftbinary ftblk ftchr ftctime ftdir fteexec fteowned fteread ftewrite ftfile ftis ftlink ftmtime ftpipe ftrexec ftrowned ftrread ftrwrite ftsgid ftsize ftsock ftsuid ftsvtx fttext fttty ftzero)], + OPpHELEMEXISTSOR_DELETE => [qw(helemexistsor)], OPpHINT_STRICT_REFS => [qw(entersub multideref rv2av rv2cv rv2gv rv2hv rv2sv)], OPpHUSH_VMSISH => [qw(dbstate nextstate)], OPpINDEX_BOOLNEG => [qw(index rindex)], |