From: Nicholas Clark Date: Mon, 5 Dec 2005 23:57:51 +0000 (+0000) Subject: Make all the return statements closer to the final calcuation of the X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8eae41ed6c62a8f34922d4cd7ac5baaf5ee54f0;p=p5sagit%2Fp5-mst-13.2.git Make all the return statements closer to the final calcuation of the returned value in the reference stringification code. Pull variables into tigher scope which also allows some to become const. p4raw-id: //depot/perl@26271 --- diff --git a/sv.c b/sv.c index 5654c58..0378b1f 100644 --- a/sv.c +++ b/sv.c @@ -2555,8 +2555,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) if (SvTHINKFIRST(sv)) { if (SvROK(sv)) { SV* tmpstr; - SV *referent; - register const char *typestr; + if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)) && (!SvROK(tmpstr) || (SvRV(tmpstr) != SvRV(sv)))) { /* Unwrap this: */ @@ -2580,12 +2579,15 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) else SvUTF8_off(sv); return pv; - } - referent = (SV*)SvRV(sv); - if (!referent) - typestr = "NULLREF"; - else { + } else { MAGIC *mg; + const SV *const referent = (SV*)SvRV(sv); + + if (!referent) { + if (lp) + *lp = 7; + return (char *)"NULLREF"; + } if (SvTYPE(referent) == SVt_PVMG && ((SvFLAGS(referent) & (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG)) @@ -2668,25 +2670,24 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) if (lp) *lp = mg->mg_len; return mg->mg_ptr; + } else { + const char *const typestr = sv_reftype(referent, 0); + + tsv = sv_newmortal(); + if (SvOBJECT(referent)) { + const char *const name = HvNAME_get(SvSTASH(referent)); + Perl_sv_setpvf(aTHX_ tsv, "%s=%s(0x%"UVxf")", + name ? name : "__ANON__" , typestr, + PTR2UV(referent)); + } + else + Perl_sv_setpvf(aTHX_ tsv, "%s(0x%"UVxf")", typestr, + PTR2UV(referent)); + if (lp) + *lp = SvCUR(tsv); + return SvPVX(tsv); } - - typestr = sv_reftype(referent, 0); - - tsv = sv_newmortal(); - if (SvOBJECT(referent)) { - const char * const name = HvNAME_get(SvSTASH(referent)); - Perl_sv_setpvf(aTHX_ tsv, "%s=%s(0x%"UVxf")", - name ? name : "__ANON__" , typestr, PTR2UV(referent)); - } - else - Perl_sv_setpvf(aTHX_ tsv, "%s(0x%"UVxf")", typestr, PTR2UV(referent)); - if (lp) - *lp = SvCUR(tsv); - return SvPVX(tsv); } - if (lp) - *lp = strlen(typestr); - return (char *)typestr; } if (SvREADONLY(sv) && !SvOK(sv)) { if (ckWARN(WARN_UNINITIALIZED))