diff options
author | Nicholas Clark <nick@ccl4.org> | 2007-10-22 12:14:12 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2007-10-22 12:14:12 +0000 |
commit | 117b69cacbec1246787bb24c539676f92ee1c4c7 (patch) | |
tree | 8b59080c915f68956e6914376030a3075a07ed60 /mro.c | |
parent | 694168e2c727557fd7c821a391f64b74290145ca (diff) | |
download | perl-117b69cacbec1246787bb24c539676f92ee1c4c7.tar.gz |
In Perl_mro_isa_changed_in(), no need to call an RVALUE hv_fetch() then
hv_store() a new HV if fetch drew a blank, as we can detect the new SV
an LVALUE fetch gave us, and replace it with a new HV, which will be
more efficient.
p4raw-id: //depot/perl@32168
Diffstat (limited to 'mro.c')
-rw-r--r-- | mro.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -550,12 +550,23 @@ Perl_mro_isa_changed_in(pTHX_ HV* stash) SV* const sv = *svp++; HV* mroisarev; - HE *he = hv_fetch_ent(PL_isarev, sv, 0, 0); - if(!he) { - he = hv_store_ent(PL_isarev, sv, (SV*)newHV(), 0); - } + HE *he = hv_fetch_ent(PL_isarev, sv, TRUE, 0); + + /* That fetch should not fail. But if it had to create a new SV for + us, then we can detect it, because it will not be the correct type. + Probably faster and cleaner for us to free that scalar [very little + code actually executed to free it] and create a new HV than to + copy&paste [SIN!] the code from newHV() to allow us to upgrade the + new SV from SVt_NULL. */ + mroisarev = (HV*)HeVAL(he); + if(SvTYPE(mroisarev) != SVt_PVHV) { + SvREFCNT_dec(mroisarev); + mroisarev = newHV(); + HeVAL(he) = (SV *) mroisarev; + } + /* This hash only ever contains PL_sv_yes. Storing it over itself is almost as cheap as calling hv_exists, so on aggregate we expect to save time by not making two calls to the common HV code for the |