From: Rafael Garcia-Suarez Date: Fri, 26 Dec 2003 10:18:24 +0000 (+0000) Subject: Refactor the code that checks whether a range is numeric X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e9bbdb923f8df09e5409a6d90b34d9a7bf447c4;p=p5sagit%2Fp5-mst-13.2.git Refactor the code that checks whether a range is numeric or string-magical. p4raw-id: //depot/perl@21960 --- diff --git a/pp_ctl.c b/pp_ctl.c index 045edd4..ab4ab84 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1031,6 +1031,16 @@ PP(pp_flip) } } +/* This code tries to decide if "$left .. $right" should use the + magical string increment, or if the range is numeric (we make + an exception for .."0" [#18165]). AMS 20021031. */ + +#define RANGE_IS_NUMERIC(left,right) ( \ + SvNIOKp(left) || !SvPOKp(left) || \ + SvNIOKp(right) || !SvPOKp(right) || \ + (looks_like_number(left) && *SvPVX(left) != '0' && \ + looks_like_number(right))) + PP(pp_flop) { dSP; @@ -1046,15 +1056,7 @@ PP(pp_flop) if (SvGMAGICAL(right)) mg_get(right); - /* This code tries to decide if "$left .. $right" should use the - magical string increment, or if the range is numeric (we make - an exception for .."0" [#18165]). AMS 20021031. */ - - if (SvNIOKp(left) || !SvPOKp(left) || - SvNIOKp(right) || !SvPOKp(right) || - (looks_like_number(left) && *SvPVX(left) != '0' && - looks_like_number(right))) - { + if (RANGE_IS_NUMERIC(left,right)) { if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX) DIE(aTHX_ "Range iterator outside integer range"); i = SvIV(left); @@ -1769,12 +1771,7 @@ PP(pp_enteriter) cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs); if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { dPOPss; - /* See comment in pp_flop() */ - if (SvNIOKp(sv) || !SvPOKp(sv) || - SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) || - (looks_like_number(sv) && *SvPVX(sv) != '0' && - looks_like_number((SV*)cx->blk_loop.iterary))) - { + if (RANGE_IS_NUMERIC(sv,(SV*)cx->blk_loop.iterary)) { if (SvNV(sv) < IV_MIN || SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX) DIE(aTHX_ "Range iterator outside integer range");