This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_iter(): optimise stack handling
[perl5.git] / pp_hot.c
index 524adeb..7b53fb9 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2625,12 +2625,11 @@ PP(pp_multideref)
 
 PP(pp_iter)
 {
-    dSP;
     PERL_CONTEXT *cx;
     SV *oldsv;
     SV **itersvp;
+    SV *retsv;
 
-    EXTEND(SP, 1);
     cx = &cxstack[cxstack_ix];
     itersvp = CxITERVAR(cx);
 
@@ -2645,7 +2644,7 @@ PP(pp_iter)
         STRLEN maxlen = 0;
         const char *max = SvPV_const(end, maxlen);
         if (UNLIKELY(SvNIOK(cur) || SvCUR(cur) > maxlen))
-            RETPUSHNO;
+            goto retno;
 
         oldsv = *itersvp;
         if (LIKELY(SvREFCNT(oldsv) == 1 && !SvMAGICAL(oldsv))) {
@@ -2671,7 +2670,7 @@ PP(pp_iter)
     {
         IV cur = cx->blk_loop.state_u.lazyiv.cur;
        if (UNLIKELY(cur > cx->blk_loop.state_u.lazyiv.end))
-           RETPUSHNO;
+           goto retno;
 
         oldsv = *itersvp;
        /* don't risk potential race */
@@ -2711,7 +2710,7 @@ PP(pp_iter)
                         ? ix > cx->blk_oldsp
                         : ix <= cx->blk_loop.state_u.stack.basesp)
         )
-            RETPUSHNO;
+            goto retno;
 
         sv = PL_stack_base[ix];
         av = NULL;
@@ -2726,7 +2725,7 @@ PP(pp_iter)
                         ? ix > AvFILL(av)
                         : ix < 0)
         )
-            RETPUSHNO;
+            goto retno;
 
         if (UNLIKELY(SvMAGICAL(av) || AvREIFY(av))) {
             SV * const * const svp = av_fetch(av, ix, FALSE);
@@ -2771,7 +2770,19 @@ PP(pp_iter)
     default:
        DIE(aTHX_ "panic: pp_iter, type=%u", CxTYPE(cx));
     }
-    RETPUSHYES;
+
+    retsv = &PL_sv_yes;
+    if (0) {
+      retno:
+        retsv = &PL_sv_no;
+    }
+    /* pp_enteriter should have pre-extended the stack */
+    assert(PL_stack_sp < PL_stack_max);
+    *++PL_stack_sp =retsv;
+
+    return PL_op->op_next;
+
+
 }
 
 /*