From: Nicholas Clark Date: Wed, 19 Sep 2007 22:52:53 +0000 (+0000) Subject: Inline and abolish S_hv_magic_uvar_xkey(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fda2d18a806c2883a36b25ff9f691418a05ccea0;p=p5sagit%2Fp5-mst-13.2.git Inline and abolish S_hv_magic_uvar_xkey(). p4raw-id: //depot/perl@31917 --- diff --git a/embed.fnc b/embed.fnc index 779cecb..8fd27a2 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1141,10 +1141,6 @@ sanR |HEK* |save_hek_flags |NN const char *str|I32 len|U32 hash|int flags sn |void |hv_magic_check |NN HV *hv|NN bool *needs_copy|NN bool *needs_store s |void |unshare_hek_or_pvn|NULLOK const HEK* hek|NULLOK const char* str|I32 len|U32 hash sR |HEK* |share_hek_flags|NN const char* sv|I32 len|U32 hash|int flags -sR |SV* |hv_magic_uvar_xkey|NN HV* hv|NULLOK SV* keysv \ - |NULLOK const char *const key \ - |const STRLEN klen |const int k_flags \ - |int action rs |void |hv_notallowed |int flags|NN const char *key|I32 klen|NN const char *msg sn |struct xpvhv_aux*|hv_auxinit|NN HV *hv sM |SV* |hv_delete_common|NULLOK HV* tb|NULLOK SV* keysv|NULLOK const char* key \ diff --git a/embed.h b/embed.h index 9c79026..edb4a3c 100644 --- a/embed.h +++ b/embed.h @@ -1142,7 +1142,6 @@ #define hv_magic_check S_hv_magic_check #define unshare_hek_or_pvn S_unshare_hek_or_pvn #define share_hek_flags S_share_hek_flags -#define hv_magic_uvar_xkey S_hv_magic_uvar_xkey #define hv_notallowed S_hv_notallowed #define hv_auxinit S_hv_auxinit #define hv_delete_common S_hv_delete_common @@ -3423,7 +3422,6 @@ #define hv_magic_check S_hv_magic_check #define unshare_hek_or_pvn(a,b,c,d) S_unshare_hek_or_pvn(aTHX_ a,b,c,d) #define share_hek_flags(a,b,c,d) S_share_hek_flags(aTHX_ a,b,c,d) -#define hv_magic_uvar_xkey(a,b,c,d,e,f) S_hv_magic_uvar_xkey(aTHX_ a,b,c,d,e,f) #define hv_notallowed(a,b,c,d) S_hv_notallowed(aTHX_ a,b,c,d) #define hv_auxinit S_hv_auxinit #define hv_delete_common(a,b,c,d,e,f,g) S_hv_delete_common(aTHX_ a,b,c,d,e,f,g) diff --git a/hv.c b/hv.c index fcff8ef..a9f4aa4 100644 --- a/hv.c +++ b/hv.c @@ -424,14 +424,29 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen, return NULL; if (SvSMAGICAL(hv) && SvGMAGICAL(hv) && !(action & HV_DISABLE_UVAR_XKEY)) { - keysv = hv_magic_uvar_xkey(hv, keysv, key, klen, flags, action); - /* If a fetch-as-store fails on the fetch, then the action is to - recurse once into "hv_store". If we didn't do this, then that - recursive call would call the key conversion routine again. - However, as we replace the original key with the converted - key, this would result in a double conversion, which would show - up as a bug if the conversion routine is not idempotent. */ - hash = 0; + MAGIC* mg; + if ((mg = mg_find((SV*)hv, PERL_MAGIC_uvar))) { + struct ufuncs * const uf = (struct ufuncs *)mg->mg_ptr; + if (uf->uf_set == NULL) { + SV* obj = mg->mg_obj; + + if (!keysv) { + keysv = sv_2mortal(newSVpvn(key, klen)); + if (flags & HVhek_UTF8) + SvUTF8_on(keysv); + } + + mg->mg_obj = keysv; /* pass key */ + uf->uf_index = action; /* pass action */ + magic_getuvar((SV*)hv, mg); + keysv = mg->mg_obj; /* may have changed */ + mg->mg_obj = obj; + + /* If the key may have changed, then we need to invalidate + any passed-in computed hash value. */ + hash = 0; + } + } } if (keysv) { if (flags & HVhek_FREEKEY) @@ -789,6 +804,12 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen, which in turn might do some tied magic. So we need to make that magic check happen. */ /* gonna assign to this, so it better be there */ + /* If a fetch-as-store fails on the fetch, then the action is to + recurse once into "hv_store". If we didn't do this, then that + recursive call would call the key conversion routine again. + However, as we replace the original key with the converted + key, this would result in a double conversion, which would show + up as a bug if the conversion routine is not idempotent. */ return hv_fetch_common(hv, keysv, key, klen, flags, HV_FETCH_ISSTORE|HV_DISABLE_UVAR_XKEY, val, hash); @@ -2524,32 +2545,6 @@ S_share_hek_flags(pTHX_ const char *str, I32 len, register U32 hash, int flags) return HeKEY_hek(entry); } -STATIC SV * -S_hv_magic_uvar_xkey(pTHX_ HV* hv, SV* keysv, const char *const key, - const STRLEN klen, const int k_flags, int action) -{ - MAGIC* mg; - if ((mg = mg_find((SV*)hv, PERL_MAGIC_uvar))) { - struct ufuncs * const uf = (struct ufuncs *)mg->mg_ptr; - if (uf->uf_set == NULL) { - SV* obj = mg->mg_obj; - - if (!keysv) { - keysv = sv_2mortal(newSVpvn(key, klen)); - if (k_flags & HVhek_UTF8) - SvUTF8_on(keysv); - } - - mg->mg_obj = keysv; /* pass key */ - uf->uf_index = action; /* pass action */ - magic_getuvar((SV*)hv, mg); - keysv = mg->mg_obj; /* may have changed */ - mg->mg_obj = obj; - } - } - return keysv; -} - I32 * Perl_hv_placeholders_p(pTHX_ HV *hv) { diff --git a/proto.h b/proto.h index cc9e27d..4aa570d 100644 --- a/proto.h +++ b/proto.h @@ -3044,10 +3044,6 @@ STATIC HEK* S_share_hek_flags(pTHX_ const char* sv, I32 len, U32 hash, int flags __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); -STATIC SV* S_hv_magic_uvar_xkey(pTHX_ HV* hv, SV* keysv, const char *const key, const STRLEN klen, const int k_flags, int action) - __attribute__warn_unused_result__ - __attribute__nonnull__(pTHX_1); - STATIC void S_hv_notallowed(pTHX_ int flags, const char *key, I32 klen, const char *msg) __attribute__noreturn__ __attribute__nonnull__(pTHX_2)