diff options
author | Gisle Aas <gisle@aas.no> | 1998-06-24 22:26:48 +0200 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-06-28 19:44:19 +0000 |
commit | 89ea29081d863efc8d483f9cbe1c4e1dbb831359 (patch) | |
tree | c7e55c90b8da9656b7bb2b9467f183842bed6aae /pp_ctl.c | |
parent | 95a449b8d7e85665d931cb07abe3a369141c3170 (diff) | |
download | perl-89ea29081d863efc8d483f9cbe1c4e1dbb831359.tar.gz |
Optimize foreach (1..1000000)
Message-ID: <m3lnqmwt93.fsf@furu.g.aas.no>
p4raw-id: //depot/perl@1239
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -815,6 +815,8 @@ PP(pp_flop) if (SvNIOKp(left) || !SvPOKp(left) || (looks_like_number(left) && *SvPVX(left) != '0') ) { + if (SvNV(left) < IV_MIN || SvNV(right) >= IV_MAX) + croak("Range iterator outside integer range"); i = SvIV(left); max = SvIV(right); if (max >= i) { @@ -832,14 +834,13 @@ PP(pp_flop) char *tmps = SvPV(final, len); sv = sv_mortalcopy(left); - while (!SvNIOKp(sv) && SvCUR(sv) <= len && - strNE(SvPVX(sv),tmps) ) { + while (!SvNIOKp(sv) && SvCUR(sv) <= len) { XPUSHs(sv); + if (strEQ(SvPVX(sv),tmps)) + break; sv = sv_2mortal(newSVsv(sv)); sv_inc(sv); } - if (strEQ(SvPVX(sv),tmps)) - XPUSHs(sv); } } else { @@ -1367,8 +1368,22 @@ PP(pp_enteriter) PUSHBLOCK(cx, CXt_LOOP, SP); PUSHLOOP(cx, svp, MARK); - if (op->op_flags & OPf_STACKED) + if (op->op_flags & OPf_STACKED) { cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs); + if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { + dPOPss; + if (SvNIOKp(sv) || !SvPOKp(sv) || + (looks_like_number(sv) && *SvPVX(sv) != '0')) { + if (SvNV(sv) < IV_MIN || + SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX) + croak("Range iterator outside integer range"); + cx->blk_loop.iterix = SvIV(sv); + cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary); + } + else + cx->blk_loop.iterlval = newSVsv(sv); + } + } else { cx->blk_loop.iterary = curstack; AvFILLp(curstack) = SP - stack_base; |