diff options
author | Nicholas Clark <nick@ccl4.org> | 2005-12-13 19:44:22 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-12-13 19:44:22 +0000 |
commit | 71c558c3bb71d4ea530abb3cc25180c1ccf2bedc (patch) | |
tree | 00538c3920b75416f0d94e0b412398a8322e4f95 /sv.c | |
parent | 91757a49c54a501fc90d7a61bceb78a9cbc4063b (diff) | |
download | perl-71c558c3bb71d4ea530abb3cc25180c1ccf2bedc.tar.gz |
Inline asIV and asUV, as each is only used once, and it distracts from
the patterns of repeated code in sv_2iv_flags, sv_2uv_flags, sv_2nv
and sv_2pv_flags. Add a comment noting the return path from the end of
the SvGMAGICAL case to all 4.
p4raw-id: //depot/perl@26345
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 100 |
1 files changed, 47 insertions, 53 deletions
@@ -1888,8 +1888,28 @@ Perl_sv_2iv_flags(pTHX_ register SV *sv, I32 flags) if (SvNOKp(sv)) { return I_V(SvNVX(sv)); } - if (SvPOKp(sv) && SvLEN(sv)) - return asIV(sv); + if (SvPOKp(sv) && SvLEN(sv)) { + UV value; + const int numtype + = grok_number(SvPVX_const(sv), SvCUR(sv), &value); + + if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) + == IS_NUMBER_IN_UV) { + /* It's definitely an integer */ + if (numtype & IS_NUMBER_NEG) { + if (value < (UV)IV_MIN) + return -(IV)value; + } else { + if (value < (UV)IV_MAX) + return (IV)value; + } + } + if (!numtype) { + if (ckWARN(WARN_NUMERIC)) + not_a_number(sv); + } + return I_V(Atof(SvPVX_const(sv))); + } if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (!PL_localizing && ckWARN(WARN_UNINITIALIZED)) @@ -1897,6 +1917,8 @@ Perl_sv_2iv_flags(pTHX_ register SV *sv, I32 flags) } return 0; } + /* Else this will drop through into the SvROK case just below, which + will return within the {} for all code paths. */ } if (SvTHINKFIRST(sv)) { if (SvROK(sv)) { @@ -1948,8 +1970,23 @@ Perl_sv_2uv_flags(pTHX_ register SV *sv, I32 flags) return SvUVX(sv); if (SvNOKp(sv)) return U_V(SvNVX(sv)); - if (SvPOKp(sv) && SvLEN(sv)) - return asUV(sv); + if (SvPOKp(sv) && SvLEN(sv)) { + UV value; + const int numtype + = grok_number(SvPVX_const(sv), SvCUR(sv), &value); + + if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) + == IS_NUMBER_IN_UV) { + /* It's definitely an integer */ + if (!(numtype & IS_NUMBER_NEG)) + return value; + } + if (!numtype) { + if (ckWARN(WARN_NUMERIC)) + not_a_number(sv); + } + return U_V(Atof(SvPVX_const(sv))); + } if (!SvROK(sv)) { if (!(SvFLAGS(sv) & SVs_PADTMP)) { if (!PL_localizing && ckWARN(WARN_UNINITIALIZED)) @@ -1957,6 +1994,8 @@ Perl_sv_2uv_flags(pTHX_ register SV *sv, I32 flags) } return 0; } + /* Else this will drop through into the SvROK case just below, which + will return within the {} for all code paths. */ } if (SvTHINKFIRST(sv)) { if (SvROK(sv)) { @@ -2023,6 +2062,8 @@ Perl_sv_2nv(pTHX_ register SV *sv) } return (NV)0; } + /* Else this will drop through into the SvROK case just below, which + will return within the {} for all code paths. */ } if (SvTHINKFIRST(sv)) { if (SvROK(sv)) { @@ -2191,55 +2232,6 @@ Perl_sv_2nv(pTHX_ register SV *sv) return SvNVX(sv); } -/* asIV(): extract an integer from the string value of an SV. - * Caller must validate PVX */ - -STATIC IV -S_asIV(pTHX_ SV *sv) -{ - UV value; - const int numtype = grok_number(SvPVX_const(sv), SvCUR(sv), &value); - - if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) - == IS_NUMBER_IN_UV) { - /* It's definitely an integer */ - if (numtype & IS_NUMBER_NEG) { - if (value < (UV)IV_MIN) - return -(IV)value; - } else { - if (value < (UV)IV_MAX) - return (IV)value; - } - } - if (!numtype) { - if (ckWARN(WARN_NUMERIC)) - not_a_number(sv); - } - return I_V(Atof(SvPVX_const(sv))); -} - -/* asUV(): extract an unsigned integer from the string value of an SV - * Caller must validate PVX */ - -STATIC UV -S_asUV(pTHX_ SV *sv) -{ - UV value; - const int numtype = grok_number(SvPVX_const(sv), SvCUR(sv), &value); - - if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) - == IS_NUMBER_IN_UV) { - /* It's definitely an integer */ - if (!(numtype & IS_NUMBER_NEG)) - return value; - } - if (!numtype) { - if (ckWARN(WARN_NUMERIC)) - not_a_number(sv); - } - return U_V(Atof(SvPVX_const(sv))); -} - /* uiv_2buf(): private routine for use by sv_2pv_flags(): print an IV or * UV as a string towards the end of buf, and return pointers to start and * end of it. @@ -2435,6 +2427,8 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) *lp = 0; return (char *)""; } + /* Else this will drop through into the SvROK case just below, which + will return within the {} for all code paths. */ } if (SvTHINKFIRST(sv)) { if (SvROK(sv)) { |