summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-12-21 13:32:13 +0000
committerDavid Mitchell <davem@iabyn.com>2016-02-03 09:18:36 +0000
commit28e0cf42294edeeb3acfd68afd6695f1f8a09632 (patch)
treecea982793e857cc8ea6524e65034db43fed66d3b /pp_ctl.c
parent6fb05a88b585ff8c2ecf0a3f089acceca1bae5b7 (diff)
downloadperl-28e0cf42294edeeb3acfd68afd6695f1f8a09632.tar.gz
only set CXp_FOR_DEF with CXp_FOR_GV
C<for (...)> is a special-case of C<for $pkg_var (...)>, so CXp_FOR_DEF should only be set when CXp_FOR_GV also is. So in pp_enteriter(), only test for (PL_op->op_private & OPpITER_DEF) in the GV branch and assert that it's otherwise unset. This is slightly more efficient in the non-GV branches. Also add some more commentary to the CXp_FOR_* flag definitions.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index bc8b778d13..3643ec5a44 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1458,7 +1458,7 @@ S_dopoptoloop(pTHX_ I32 startingblock)
return i;
}
-/* find the next GIVEN or FOR loop context block */
+/* find the next GIVEN or FOR (with implicit $_) loop context block */
STATIC I32
S_dopoptogivenfor(pTHX_ I32 startingblock)
@@ -2126,6 +2126,8 @@ PP(pp_enteriter)
itersave = GvSV(sv);
SvREFCNT_inc_simple_void(itersave);
cxflags = CXp_FOR_GV;
+ if (PL_op->op_private & OPpITER_DEF)
+ cxflags |= CXp_FOR_DEF;
}
else { /* LV ref: for \$foo (...) */
assert(SvTYPE(sv) == SVt_PVMG);
@@ -2135,9 +2137,8 @@ PP(pp_enteriter)
cxflags = CXp_FOR_LVREF;
}
}
-
- if (PL_op->op_private & OPpITER_DEF)
- cxflags |= CXp_FOR_DEF;
+ /* OPpITER_DEF (implicit $_) should only occur with a GV iter var */
+ assert((cxflags & CXp_FOR_GV) || !(PL_op->op_private & OPpITER_DEF));
PUSHBLOCK(cx, cxflags, MARK);
PUSHLOOP_FOR(cx, itervarp, itersave);