summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-04-27 06:00:14 +0000
committerRicardo Signes <rjbs@semiotic.systems>2021-10-15 09:28:27 -0400
commitd9b6ecc18fa9d0af456180eceeef05148bcfdf9f (patch)
tree7ef6c7824d61aee893e66b8009ca18f54678c408 /pp_hot.c
parentbf6e71ff82686b1287ef59c1565cc669d5301cc5 (diff)
downloadperl-d9b6ecc18fa9d0af456180eceeef05148bcfdf9f.tar.gz
Move reading CxTYPE(cx) out of the loop, to be clear that it doesn't change.
Move some other variable declarations into a tighter scope, and initialise variables at the point of declaration where possible. With the recent changes, the function consists of a 4-way switch inside a loop, where each iteration of the loop will take the same case in the switch. This implies a branch taken on each iteration of the loop, which is less efficient than the alternative structure of taking the branch once and then looping. However, the way the code is structured (particularly how two of the cases share code, by jumping sideways), means that rewriting it to "switch first" structure would not be clearer (and likely would also be hard to get right). Hence it seems better to let a compiler optimiser choose what is best. However, it might not realise that CxTYPE(cx) won't be changed, even as a side effect of any function called by this code. Hence hoist it into a constant variable to make this unequivocal.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 316a26a665..bce4c1fca0 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3897,14 +3897,9 @@ PP(pp_multideref)
PP(pp_iter)
{
- PERL_CONTEXT *cx;
- SV *oldsv;
- SV **itersvp;
-
- SV *sv;
- AV *av;
- IV ix;
- IV inc;
+ PERL_CONTEXT *cx = CX_CUR();
+ SV **itersvp = CxITERVAR(cx);
+ const U8 type = CxTYPE(cx);
/* Classic "for" syntax iterates one-at-a-time.
Many-at-a-time for loops are only for lexicals declared as part of the
@@ -3920,12 +3915,16 @@ PP(pp_iter)
PADOFFSET how_many = PL_op->op_targ;
PADOFFSET i = 0;
- cx = CX_CUR();
- itersvp = CxITERVAR(cx);
assert(itersvp);
for (; i <= how_many; ++i ) {
- switch (CxTYPE(cx)) {
+ SV *oldsv;
+ SV *sv;
+ AV *av;
+ IV ix;
+ IV inc;
+
+ switch (type) {
case CXt_LOOP_LAZYSV: /* string increment */
{