From: bulk88 (via RT) Date: Fri, 23 Nov 2012 00:33:34 +0000 (-0800) Subject: av_exists: dont make a mortal never to use it X-Git-Tag: upstream/5.20.0~4710 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=716ae3b03e04a6b0ae19b882828eecf4ffc4c458;p=platform%2Fupstream%2Fperl.git av_exists: dont make a mortal never to use it Make av_exists slightly smaller and faster by reducing the liveness of a mortal SV and using a NN SvTRUE_nomg. There were 3 cases, where this mortal would be created, yet a return happened and the mortal went unused and was wasted. So move the mortal creation point closer to where it is first used. Also var sv will never be null, so use a NN version of SvTRUE_nomg created in commit [perl #115870]. The retbool line isn't actually required for optimization reasons, but was created just in case something in the future changes or some unknown compiler does something inefficiently. For me with 32 bit x86 VC 2003, before av_exists was 0x1C2, after 0x1B8. Comment from committer: Includes SvTRUE_nomg_NN from [perl #115870]. --- diff --git a/av.c b/av.c index 6d2b949..cfa5399 100644 --- a/av.c +++ b/av.c @@ -934,7 +934,6 @@ Perl_av_exists(pTHX_ AV *av, I32 key) const MAGIC * const regdata_magic = mg_find((const SV *)av, PERL_MAGIC_regdata); if (tied_magic || regdata_magic) { - SV * const sv = sv_newmortal(); MAGIC *mg; /* Handle negative array indices 20020222 MJD */ if (key < 0) { @@ -948,14 +947,18 @@ Perl_av_exists(pTHX_ AV *av, I32 key) else return FALSE; } - - mg_copy(MUTABLE_SV(av), sv, 0, key); - mg = mg_find(sv, PERL_MAGIC_tiedelem); - if (mg) { - magic_existspack(sv, mg); - return cBOOL(SvTRUE_nomg(sv)); - } - + { + SV * const sv = sv_newmortal(); + mg_copy(MUTABLE_SV(av), sv, 0, key); + mg = mg_find(sv, PERL_MAGIC_tiedelem); + if (mg) { + magic_existspack(sv, mg); + { + I32 retbool = SvTRUE_nomg_NN(sv); + return cBOOL(retbool); + } + } + } } } diff --git a/sv.h b/sv.h index 35b360f..fe29a41 100644 --- a/sv.h +++ b/sv.h @@ -1709,6 +1709,7 @@ Like sv_utf8_upgrade, but doesn't do magic on C. #define SvTRUE(sv) ((sv) && (SvGMAGICAL(sv) ? sv_2bool(sv) : SvTRUE_common(sv, sv_2bool_nomg(sv)))) #define SvTRUE_nomg(sv) ((sv) && ( SvTRUE_common(sv, sv_2bool_nomg(sv)))) #define SvTRUE_NN(sv) (SvGMAGICAL(sv) ? sv_2bool(sv) : SvTRUE_common(sv, sv_2bool_nomg(sv))) +#define SvTRUE_nomg_NN(sv) ( SvTRUE_common(sv, sv_2bool_nomg(sv))) #define SvTRUE_common(sv,fallback) ( \ !SvOK(sv) \ ? 0 \