summaryrefslogtreecommitdiff
path: root/regen/op_private
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-08-02 21:48:26 +0000
committerRichard Leach <richardleach@users.noreply.github.com>2022-10-24 23:21:17 +0100
commit10a5c9138224597d018843f3b298a928555b67f0 (patch)
tree008b756c7b5f34777576c94ebca07c22ee4c271f /regen/op_private
parent71a3dd321d7fa8259a22a1ca1e87aa820a8deef2 (diff)
downloadperl-10a5c9138224597d018843f3b298a928555b67f0.tar.gz
OP_EMPTYAVHV - optimized empty ANONLIST/ANONHASH
This commit introduces a new OP to replace cases of OP_ANONLIST and OP_ANONHASH where there are zero elements, which is very common in Perl code. As an example, `my $x = {}` is currently implemented like this: ... 6 <2> sassign vKS/2 ->7 4 <@> anonhash sK* ->5 3 <0> pushmark s ->4 5 <0> padsv[$x:1,2] sRM*/LVINTRO ->6 The pushmark serves no meaningful purpose when there are zero elements and the anonhash, besides undoing the pushmark, performs work that is unnecessary for this special case. The peephole optimizer, which also checks for applicability of a related TARGMY optimization, transforms this example into: ... - <1> ex-sassign vKS/2 ->4 3 <@> emptyavhv[$x:1,2] vK*/LVINTRO,ANONHASH,TARGMY ->4 - <0> ex-pushmark s ->3 - <0> ex-padsv sRM*/LVINTRO ->-
Diffstat (limited to 'regen/op_private')
-rw-r--r--regen/op_private11
1 files changed, 9 insertions, 2 deletions
diff --git a/regen/op_private b/regen/op_private
index 4f2afe2174..7150f20cc8 100644
--- a/regen/op_private
+++ b/regen/op_private
@@ -318,7 +318,7 @@ addbits($_, 7 => qw(OPpLVAL_INTRO LVINTRO))
for qw(gvsv rv2sv rv2hv rv2gv rv2av aelem helem aslice split
hslice delete padsv padav padhv enteriter entersub padrange
pushmark cond_expr refassign lvref lvrefslice lvavref multideref
- multiconcat padsv_store undef),
+ multiconcat padsv_store undef emptyavhv),
'list', # this gets set in my_attrs() for some reason
;
@@ -500,7 +500,7 @@ addbits($_, 7 => qw(OPpPV_IS_UTF8 UTF)) for qw(last redo next goto dump);
addbits($_, 6 => qw(OPpPAD_STATE STATE)) for qw(padav padhv padsv lvavref
lvref refassign pushmark
- padsv_store undef);
+ padsv_store undef emptyavhv);
# NB: both sassign and aassign use the 'OPpASSIGN' naming convention
# for their private flags
@@ -860,6 +860,13 @@ addbits('undef',
5 => qw(OPpUNDEF_KEEP_PV KEEP_PV),
);
+addbits('emptyavhv',
+ # 7 OPpLVAL_INTRO
+ # 6 OPpPAD_STATE
+ 5 => qw(OPpEMPTYAVHV_IS_HV ANONHASH),
+ # 4 OPpTARGET_MY
+);
+
1;
# ex: set ts=8 sts=4 sw=4 et: