From: Nicholas Clark Date: Sat, 28 Jan 2006 13:38:28 +0000 (+0000) Subject: By changing SvVOK() from returning 0/1 to 0/pointer-to-magic we can X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4f2da183afece5ce28d1dcdb66d8d931eb0d976a;p=p5sagit%2Fp5-mst-13.2.git By changing SvVOK() from returning 0/1 to 0/pointer-to-magic we can save duplicating mg_find calls, without changing the semantics in any boolean context. p4raw-id: //depot/perl@26979 --- diff --git a/sv.c b/sv.c index 913d4c8..f48aa8b 100644 --- a/sv.c +++ b/sv.c @@ -3417,11 +3417,13 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) SvIsUV_on(dstr); SvIV_set(dstr, SvIVX(sstr)); } - if (SvVOK(sstr)) { - const MAGIC * const smg = mg_find(sstr,PERL_MAGIC_vstring); - sv_magic(dstr, NULL, PERL_MAGIC_vstring, - smg->mg_ptr, smg->mg_len); - SvRMAGICAL_on(dstr); + { + const MAGIC * const smg = SvVOK(sstr); + if (smg) { + sv_magic(dstr, NULL, PERL_MAGIC_vstring, + smg->mg_ptr, smg->mg_len); + SvRMAGICAL_on(dstr); + } } } else if (sflags & SVp_IOK) { diff --git a/sv.h b/sv.h index 58c078f..d8597ad 100644 --- a/sv.h +++ b/sv.h @@ -751,7 +751,8 @@ in gv.h: */ SVf_IVisUV), \ SvFLAGS(sv) |= (SVf_POK|SVp_POK)) -#define SvVOK(sv) (SvMAGICAL(sv) && mg_find(sv,'V')) +#define SvVOK(sv) (SvMAGICAL(sv) \ + ? mg_find(sv,PERL_MAGIC_vstring) : NULL) #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) #define SvOOK_off(sv) ((void)(SvOOK(sv) && sv_backoff(sv))) diff --git a/util.c b/util.c index abbf4ed..dbd2d2d 100644 --- a/util.c +++ b/util.c @@ -4170,17 +4170,19 @@ Perl_new_version(pTHX_ SV *ver) return rv; } #ifdef SvVOK - if ( SvVOK(ver) ) { /* already a v-string */ - const MAGIC* const mg = mg_find(ver,PERL_MAGIC_vstring); - const STRLEN len = mg->mg_len; - char * const version = savepvn( (const char*)mg->mg_ptr, len); - sv_setpvn(rv,version,len); - Safefree(version); - } - else { + { + const MAGIC* const mg = SvVOK(ver); + if ( mg ) { /* already a v-string */ + const STRLEN len = mg->mg_len; + char * const version = savepvn( (const char*)mg->mg_ptr, len); + sv_setpvn(rv,version,len); + Safefree(version); + } + else { #endif - sv_setsv(rv,ver); /* make a duplicate */ + sv_setsv(rv,ver); /* make a duplicate */ #ifdef SvVOK + } } #endif return upg_version(rv); @@ -4203,6 +4205,9 @@ Perl_upg_version(pTHX_ SV *ver) { const char *version, *s; bool qv = 0; +#ifdef SvVOK + const MAGIC *mg; +#endif if ( SvNOK(ver) ) /* may get too much accuracy */ { @@ -4211,8 +4216,7 @@ Perl_upg_version(pTHX_ SV *ver) version = savepvn(tbuf, len); } #ifdef SvVOK - else if ( SvVOK(ver) ) { /* already a v-string */ - const MAGIC* const mg = mg_find(ver,PERL_MAGIC_vstring); + else if ( (mg = SvVOK(ver)) ) { /* already a v-string */ version = savepvn( (const char*)mg->mg_ptr,mg->mg_len ); qv = 1; }