From fcef60b407682ad7861f3c827053d6345b02bf20 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Tue, 13 Nov 2012 12:51:05 +0000 Subject: [PATCH] pp_iter: refactor CXt_LOOP_LAZYIV branch --- pp_hot.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 538c121..25c3810 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1937,32 +1937,34 @@ PP(pp_iter) break; } - case CXt_LOOP_LAZYIV: - /* integer increment */ - if (cx->blk_loop.state_u.lazyiv.cur > cx->blk_loop.state_u.lazyiv.end) + case CXt_LOOP_LAZYIV: /* integer increment */ + { + IV cur = cx->blk_loop.state_u.lazyiv.cur; + if (cur > cx->blk_loop.state_u.lazyiv.end) RETPUSHNO; + oldsv = *itersvp; /* don't risk potential race */ - if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) { + if (SvREFCNT(oldsv) == 1 && !SvMAGICAL(oldsv)) { /* safe to reuse old SV */ - sv_setiv(*itersvp, cx->blk_loop.state_u.lazyiv.cur); + sv_setiv(oldsv, cur); } else { /* we need a fresh SV every time so that loop body sees a * completely new SV for closures/references to work as they * used to */ - oldsv = *itersvp; - *itersvp = newSViv(cx->blk_loop.state_u.lazyiv.cur); + *itersvp = newSViv(cur); SvREFCNT_dec(oldsv); } - if (cx->blk_loop.state_u.lazyiv.cur == IV_MAX) { + if (cur == IV_MAX) { /* Handle end of range at IV_MAX */ cx->blk_loop.state_u.lazyiv.end = IV_MIN; } else ++cx->blk_loop.state_u.lazyiv.cur; break; + } case CXt_LOOP_FOR: { -- 2.7.4