This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_enteriter, POPLOOP: simplify some code
authorDavid Mitchell <davem@iabyn.com>
Fri, 28 Aug 2015 07:37:42 +0000 (08:37 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:39 +0000 (08:59 +0000)
merge some common code from branch arms and tidy up. Shouldn't make
any functional difference.

cop.h
pp_ctl.c

diff --git a/cop.h b/cop.h
index c708cb7..cf2cca7 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -831,17 +831,12 @@ struct block_loop {
        else if (CxTYPE(cx) == CXt_LOOP_FOR)                            \
            SvREFCNT_dec(cx->blk_loop.state_u.ary.ary);                 \
         if (cx->cx_type & (CXp_FOR_PAD|CXp_FOR_GV)) {                   \
-            SV **svp = (cx)->blk_loop.itervar_u.svp;                    \
             SV *cursv;                                                  \
-            if ((cx->cx_type & CXp_FOR_GV)) {                           \
+            SV **svp = (cx)->blk_loop.itervar_u.svp;                    \
+            if ((cx->cx_type & CXp_FOR_GV))                             \
                 svp = &GvSV((GV*)svp);                                  \
-                cursv = *svp;                                           \
-                *svp = cx->blk_loop.itersave;                           \
-            }                                                           \
-            else {                                                      \
-                cursv = *svp;                                           \
-                *svp = cx->blk_loop.itersave;                           \
-            }                                                           \
+            cursv = *svp;                                               \
+            *svp = cx->blk_loop.itersave;                               \
             SvREFCNT_dec(cursv);                                        \
         }
 
index 1ba7800..4aeac8a 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2137,25 +2137,25 @@ PP(pp_enteriter)
         SvREFCNT_inc_simple_void_NN(itersave);
        cxtype |= CXp_FOR_PAD;
     }
-    else if (LIKELY(isGV(TOPs))) {             /* symbol table variable */
-       GV * const gv = MUTABLE_GV(POPs);
-       SV** svp = &GvSV(gv);
-       itervarp = (void *)gv;
-        itersave = *svp;
-        if (LIKELY(itersave))
-            SvREFCNT_inc_simple_void_NN(itersave);
-        else
-            *svp = newSV(0);
-       cxtype |= CXp_FOR_GV;
-    }
     else {
        SV * const sv = POPs;
-       assert(SvTYPE(sv) == SVt_PVMG);
-       assert(SvMAGIC(sv));
-       assert(SvMAGIC(sv)->mg_type == PERL_MAGIC_lvref);
        itervarp = (void *)sv;
-       cxtype |= CXp_FOR_LVREF;
-        itersave = NULL;
+        if (LIKELY(isGV(sv))) {                /* symbol table variable */
+            SV** svp = &GvSV(sv);
+            itersave = *svp;
+            if (LIKELY(itersave))
+                SvREFCNT_inc_simple_void_NN(itersave);
+            else
+                *svp = newSV(0);
+            cxtype |= CXp_FOR_GV;
+        }
+        else {                          /* LV ref: for \$foo (...) */
+            assert(SvTYPE(sv) == SVt_PVMG);
+            assert(SvMAGIC(sv));
+            assert(SvMAGIC(sv)->mg_type == PERL_MAGIC_lvref);
+            itersave = NULL;
+            cxtype |= CXp_FOR_LVREF;
+        }
     }
 
     if (PL_op->op_private & OPpITER_DEF)