Faster foreach integer range
authorGisle Aas <gisle@aas.no>
Tue, 7 Jul 1998 11:48:11 +0000 (13:48 +0200)
committerGurusamy Sarathy <gsar@cpan.org>
Wed, 8 Jul 1998 02:30:55 +0000 (02:30 +0000)
Message-ID: <m3k95qm1pg.fsf@furu.g.aas.no>

p4raw-id: //depot/perl@1367

pp_ctl.c
pp_hot.c

index bdc371f..b1d2f68 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1388,6 +1388,7 @@ PP(pp_enteriter)
                     croak("Range iterator outside integer range");
                 cx->blk_loop.iterix = SvIV(sv);
                 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
+                sv_setiv(*svp, 0); /* make sure index SV is IV capable */
            }
            else
                cx->blk_loop.iterlval = newSVsv(sv);
index b52563a..f7183a8 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1459,7 +1459,14 @@ PP(pp_iter)
        /* integer increment */
        if (cx->blk_loop.iterix > cx->blk_loop.itermax)
            RETPUSHNO;
-       sv_setiv(*cx->blk_loop.itervar, cx->blk_loop.iterix++);
+
+       /* we know that the loop index SV is IV capable, so we can save
+        * some time by doing the essential work of sv_setiv() ourself.
+        */
+       sv = *cx->blk_loop.itervar;
+       (void)SvIOK_only(sv);
+       SvIVX(sv) = cx->blk_loop.iterix++;
+
        RETPUSHYES;
     }