diff options
author | Dave Mitchell <davem@fdisolutions.com> | 2008-12-09 19:29:47 +0000 |
---|---|---|
committer | Dave Mitchell <davem@fdisolutions.com> | 2008-12-09 19:29:47 +0000 |
commit | a147231165ce49500e77dc9df830c22e9aea04c7 (patch) | |
tree | 28c0dcb58b1f5056117998fb28c2bee69d76e477 | |
parent | 281b372ab1f99be667369ed62d4d375f821a0122 (diff) | |
download | perl-a147231165ce49500e77dc9df830c22e9aea04c7.tar.gz |
Integrate:
[ 34190]
Don't bother hashing the key, or performing any other preparatory work,
if there isn't anything to find.
p4raw-link: @34190 on //depot/perl: cd1d2f8a20b8a9f92576c0e00d1dc723574ea002
p4raw-id: //depot/maint-5.10/perl@35064
p4raw-integrated: from //depot/perl@34190 'merge in' hv.c (@33814..)
-rw-r--r-- | hv.c | 76 |
1 files changed, 40 insertions, 36 deletions
@@ -2637,49 +2637,53 @@ Perl_refcounted_he_fetch(pTHX_ const struct refcounted_he *chain, SV *keysv, /* Just to be awkward, if you're using this interface the UTF-8-or-not-ness of your key has to exactly match that which is stored. */ SV *value = &PL_sv_placeholder; - bool is_utf8; - if (keysv) { - if (flags & HVhek_FREEKEY) - Safefree(key); - key = SvPV_const(keysv, klen); - flags = 0; - is_utf8 = (SvUTF8(keysv) != 0); - } else { - is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE); - } + if (chain) { + /* No point in doing any of this if there's nothing to find. */ + bool is_utf8; - if (!hash) { - if (keysv && (SvIsCOW_shared_hash(keysv))) { - hash = SvSHARED_HASH(keysv); - } else { - PERL_HASH(hash, key, klen); - } - } + if (keysv) { + if (flags & HVhek_FREEKEY) + Safefree(key); + key = SvPV_const(keysv, klen); + flags = 0; + is_utf8 = (SvUTF8(keysv) != 0); + } else { + is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE); + } + + if (!hash) { + if (keysv && (SvIsCOW_shared_hash(keysv))) { + hash = SvSHARED_HASH(keysv); + } else { + PERL_HASH(hash, key, klen); + } + } - for (; chain; chain = chain->refcounted_he_next) { + for (; chain; chain = chain->refcounted_he_next) { #ifdef USE_ITHREADS - if (hash != chain->refcounted_he_hash) - continue; - if (klen != chain->refcounted_he_keylen) - continue; - if (memNE(REF_HE_KEY(chain),key,klen)) - continue; - if (!!is_utf8 != !!(chain->refcounted_he_data[0] & HVhek_UTF8)) - continue; + if (hash != chain->refcounted_he_hash) + continue; + if (klen != chain->refcounted_he_keylen) + continue; + if (memNE(REF_HE_KEY(chain),key,klen)) + continue; + if (!!is_utf8 != !!(chain->refcounted_he_data[0] & HVhek_UTF8)) + continue; #else - if (hash != HEK_HASH(chain->refcounted_he_hek)) - continue; - if (klen != (STRLEN)HEK_LEN(chain->refcounted_he_hek)) - continue; - if (memNE(HEK_KEY(chain->refcounted_he_hek),key,klen)) - continue; - if (!!is_utf8 != !!HEK_UTF8(chain->refcounted_he_hek)) - continue; + if (hash != HEK_HASH(chain->refcounted_he_hek)) + continue; + if (klen != (STRLEN)HEK_LEN(chain->refcounted_he_hek)) + continue; + if (memNE(HEK_KEY(chain->refcounted_he_hek),key,klen)) + continue; + if (!!is_utf8 != !!HEK_UTF8(chain->refcounted_he_hek)) + continue; #endif - value = sv_2mortal(refcounted_he_value(chain)); - break; + value = sv_2mortal(refcounted_he_value(chain)); + break; + } } if (flags & HVhek_FREEKEY) |