summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorGisle Aas <gisle@aas.no>1998-06-24 22:26:48 +0200
committerGurusamy Sarathy <gsar@cpan.org>1998-06-28 19:44:19 +0000
commit89ea29081d863efc8d483f9cbe1c4e1dbb831359 (patch)
treec7e55c90b8da9656b7bb2b9467f183842bed6aae /pp_hot.c
parent95a449b8d7e85665d931cb07abe3a369141c3170 (diff)
downloadperl-89ea29081d863efc8d483f9cbe1c4e1dbb831359.tar.gz
Optimize foreach (1..1000000)
Message-ID: <m3lnqmwt93.fsf@furu.g.aas.no> p4raw-id: //depot/perl@1239
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/pp_hot.c b/pp_hot.c
index dd5ef14e8a..8331bb36a9 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1403,6 +1403,31 @@ PP(pp_iter)
DIE("panic: pp_iter");
av = cx->blk_loop.iterary;
+ if (SvTYPE(av) != SVt_PVAV) {
+ /* iterate ($min .. $max) */
+ if (cx->blk_loop.iterlval) {
+ /* string increment */
+ register SV* cur = cx->blk_loop.iterlval;
+ STRLEN maxlen;
+ char *max = SvPV((SV*)av, maxlen);
+ if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
+ sv_setsv(*cx->blk_loop.itervar, cur);
+ if (strEQ(SvPVX(cur), max))
+ sv_setiv(cur, 0); /* terminate next time */
+ else
+ sv_inc(cur);
+ RETPUSHYES;
+ }
+ RETPUSHNO;
+ }
+ /* integer increment */
+ if (cx->blk_loop.iterix > cx->blk_loop.itermax)
+ RETPUSHNO;
+ sv_setiv(*cx->blk_loop.itervar, cx->blk_loop.iterix++);
+ RETPUSHYES;
+ }
+
+ /* iterate array */
if (cx->blk_loop.iterix >= (av == curstack ? cx->blk_oldsp : AvFILL(av)))
RETPUSHNO;