From: Nicholas Clark Date: Wed, 19 Sep 2007 22:04:46 +0000 (+0000) Subject: Send all delete()/delete_ent() calls via S_hv_fetch_common(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9dbc5603217e015b4c096a784947b1930341263c;p=p5sagit%2Fp5-mst-13.2.git Send all delete()/delete_ent() calls via S_hv_fetch_common(). This puts all the key normalisation code in one place. p4raw-id: //depot/perl@31916 --- diff --git a/hv.c b/hv.c index 7697fea..fcff8ef 100644 --- a/hv.c +++ b/hv.c @@ -443,6 +443,12 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen, is_utf8 = ((flags & HVhek_UTF8) ? TRUE : FALSE); } + if (action & HV_DELETE) { + return (HE *) hv_delete_common(hv, keysv, key, klen, + flags | (is_utf8 ? HVhek_UTF8 : 0), + action, hash); + } + xhv = (XPVHV*)SvANY(hv); if (SvMAGICAL(hv)) { if (SvRMAGICAL(hv) && !(action & (HV_FETCH_ISSTORE|HV_FETCH_ISEXISTS))) { @@ -930,7 +936,8 @@ Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags) klen = klen_i32; k_flags = 0; } - return hv_delete_common(hv, NULL, key, klen, k_flags, flags, 0); + return (SV *) hv_fetch_common(hv, NULL, key, klen, k_flags, + flags | HV_DELETE, NULL, 0); } /* @@ -948,7 +955,8 @@ precomputed hash value, or 0 to ask for it to be computed. SV * Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash) { - return hv_delete_common(hv, keysv, NULL, 0, 0, flags, hash); + return (SV *) hv_fetch_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, + NULL, hash); } STATIC SV * @@ -960,27 +968,9 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen, register HE *entry; register HE **oentry; HE *const *first_entry; - bool is_utf8; + bool is_utf8 = (k_flags & HVhek_UTF8) ? TRUE : FALSE; int masked_flags; - if (!hv) - return NULL; - - if (SvSMAGICAL(hv) && SvGMAGICAL(hv) - && !(d_flags & HV_DISABLE_UVAR_XKEY)) { - keysv = hv_magic_uvar_xkey(hv, keysv, key, klen, k_flags, HV_DELETE); - hash = 0; - } - if (keysv) { - if (k_flags & HVhek_FREEKEY) - Safefree(key); - key = SvPV_const(keysv, klen); - k_flags = 0; - is_utf8 = (SvUTF8(keysv) != 0); - } else { - is_utf8 = ((k_flags & HVhek_UTF8) ? TRUE : FALSE); - } - if (SvRMAGICAL(hv)) { bool needs_copy; bool needs_store; diff --git a/hv.h b/hv.h index dfcc591..bb4a3e0 100644 --- a/hv.h +++ b/hv.h @@ -482,7 +482,6 @@ struct refcounted_he { /* Hash actions * Passed in PERL_MAGIC_uvar calls */ -#define HV_DELETE -1 #define HV_DISABLE_UVAR_XKEY 0x01 /* We need to ensure that these don't clash with G_DISCARD, which is 2, as it is documented as being passed to hv_delete(). */ @@ -490,6 +489,7 @@ struct refcounted_he { #define HV_FETCH_ISEXISTS 0x08 #define HV_FETCH_LVALUE 0x10 #define HV_FETCH_JUST_SV 0x20 +#define HV_DELETE 0x40 /* * Local variables: