From: Nicholas Clark Date: Thu, 24 Jan 2008 13:25:05 +0000 (+0000) Subject: Merge CXt_LOOP_STACK's use of itermax for the reverse minimum with X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c25bf6989edf21dd302c4e306179cfffbc11bb5f;p=p5sagit%2Fp5-mst-13.2.git Merge CXt_LOOP_STACK's use of itermax for the reverse minimum with iterary, as the two structure members are not used simultaneously. p4raw-id: //depot/perl@33062 --- diff --git a/cop.h b/cop.h index fd8e9fa..7c50537 100644 --- a/cop.h +++ b/cop.h @@ -446,11 +446,15 @@ struct block_loop { /* (from inspection of source code) for a .. range of strings this is the current string. */ SV * iterlval; + union { /* (from inspection of source code) for a foreach loop this is the array being iterated over. For a .. range of numbers it's the current value. A check is often made on the SvTYPE of iterary to determine whether we are iterating over an array or a range. (numbers or strings) */ - AV * iterary; + AV * iterary; + /* Minimum stack index when reverse iterating as CXt_LOOP_STACK */ + IV itermin; + } ary_min_u; IV iterix; /* (from inspection of source code) for a .. range of numbers this is the maximum value. */ @@ -505,7 +509,7 @@ struct block_loop { cx->blk_loop.my_op = cLOOP; \ PUSHLOOP_OP_NEXT; \ cx->blk_loop.iterlval = NULL; \ - cx->blk_loop.iterary = NULL; \ + cx->blk_loop.ary_min_u.iterary = NULL; \ CX_ITERDATA_SET(cx,NULL); #define PUSHLOOP_FOR(cx, dat, s) \ @@ -513,7 +517,7 @@ struct block_loop { cx->blk_loop.my_op = cLOOP; \ PUSHLOOP_OP_NEXT; \ cx->blk_loop.iterlval = NULL; \ - cx->blk_loop.iterary = NULL; \ + cx->blk_loop.ary_min_u.iterary = NULL; \ cx->blk_loop.iterix = -1; \ CX_ITERDATA_SET(cx,dat); @@ -531,8 +535,8 @@ struct block_loop { SvREFCNT_dec(cx->blk_loop.itersave); \ } \ } \ - if ((CxTYPE(cx) != CXt_LOOP_STACK) && cx->blk_loop.iterary) \ - SvREFCNT_dec(cx->blk_loop.iterary); + if ((CxTYPE(cx) != CXt_LOOP_STACK) && cx->blk_loop.ary_min_u.iterary) \ + SvREFCNT_dec(cx->blk_loop.ary_min_u.iterary); /* given/when context */ struct block_givwhen { diff --git a/pp_ctl.c b/pp_ctl.c index 7968eb9..baacd41 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1881,10 +1881,10 @@ PP(pp_enteriter) PUSHLOOP_FOR(cx, svp, MARK); #endif if (PL_op->op_flags & OPf_STACKED) { - cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs); - if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { + cx->blk_loop.ary_min_u.iterary = (AV*)SvREFCNT_inc(POPs); + if (SvTYPE(cx->blk_loop.ary_min_u.iterary) != SVt_PVAV) { dPOPss; - SV * const right = (SV*)cx->blk_loop.iterary; + SV * const right = (SV*)cx->blk_loop.ary_min_u.iterary; SvGETMAGIC(sv); SvGETMAGIC(right); if (RANGE_IS_NUMERIC(sv,right)) { @@ -1927,14 +1927,13 @@ PP(pp_enteriter) } else if (PL_op->op_private & OPpITER_REVERSED) { cx->blk_loop.itermax = 0xDEADBEEF; - cx->blk_loop.iterix = AvFILL(cx->blk_loop.iterary) + 1; + cx->blk_loop.iterix = AvFILL(cx->blk_loop.ary_min_u.iterary) + 1; } } else { - cx->blk_loop.iterary = (AV*)0xDEADBEEF; if (PL_op->op_private & OPpITER_REVERSED) { - cx->blk_loop.itermax = MARK - PL_stack_base + 1; + cx->blk_loop.ary_min_u.itermin = MARK - PL_stack_base + 1; cx->blk_loop.iterix = cx->blk_oldsp + 1; } else { diff --git a/pp_hot.c b/pp_hot.c index ca0b4ab..f963f0c 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1911,7 +1911,8 @@ PP(pp_iter) DIE(aTHX_ "panic: pp_iter"); itersvp = CxITERVAR(cx); - av = CxTYPE(cx) == CXt_LOOP_STACK ? PL_curstack : cx->blk_loop.iterary; + av = (CxTYPE(cx) == CXt_LOOP_STACK) + ? PL_curstack : cx->blk_loop.ary_min_u.iterary; if (SvTYPE(av) != SVt_PVAV) { /* iterate ($min .. $max) */ if (CxTYPE(cx) != CXt_LOOP_LAZYIV) { @@ -1978,7 +1979,7 @@ PP(pp_iter) if (PL_op->op_private & OPpITER_REVERSED) { /* In reverse, use itermax as the min :-) */ if (cx->blk_loop.iterix <= (CxTYPE(cx) == CXt_LOOP_STACK - ? cx->blk_loop.itermax : 0)) + ? cx->blk_loop.ary_min_u.itermin : 0)) RETPUSHNO; if (SvMAGICAL(av) || AvREIFY(av)) { diff --git a/scope.c b/scope.c index c8f190f..e02a302 100644 --- a/scope.c +++ b/scope.c @@ -1097,7 +1097,7 @@ Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n", (long)cx->blk_loop.iterix); PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n", - PTR2UV(cx->blk_loop.iterary)); + PTR2UV(cx->blk_loop.ary_min_u.iterary)); PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n", PTR2UV(CxITERVAR(cx))); if (CxITERVAR(cx)) diff --git a/sv.c b/sv.c index 33293a5..514a775 100644 --- a/sv.c +++ b/sv.c @@ -10544,8 +10544,8 @@ Perl_cx_dup(pTHX_ PERL_CONTEXT *cxs, I32 ix, I32 max, CLONE_PARAMS* param) break; case CXt_LOOP_LAZYIV: case CXt_LOOP_FOR: - ncx->blk_loop.iterary = av_dup_inc(ncx->blk_loop.iterary, - param); + ncx->blk_loop.ary_min_u.iterary + = av_dup_inc(ncx->blk_loop.ary_min_u.iterary, param); case CXt_LOOP_STACK: case CXt_LOOP_PLAIN: ncx->blk_loop.iterdata = (CxPADLOOP(ncx)