Skip to content

Commit

Permalink
Make hv_fetch_common() non-static, and change its name to hv_common(),
Browse files Browse the repository at this point in the history
as it now also performs hv_delete()/hv_delete_ent()

p4raw-id: //depot/perl@31919
  • Loading branch information
nwc10 committed Sep 20, 2007
1 parent c74c7a1 commit d3ba3f5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
5 changes: 3 additions & 2 deletions embed.fnc
Expand Up @@ -304,6 +304,9 @@ ApdR |bool |hv_exists |NULLOK HV* tb|NN const char* key|I32 klen
ApdR |bool |hv_exists_ent |NULLOK HV* tb|NN SV* key|U32 hash
Apd |SV** |hv_fetch |NULLOK HV* tb|NN const char* key|I32 klen|I32 lval
Apd |HE* |hv_fetch_ent |NULLOK HV* tb|NN SV* key|I32 lval|U32 hash
Ap |HE* |hv_common |NULLOK HV* tb|NULLOK SV* keysv \
|NULLOK const char* key|STRLEN klen|int flags \
|int action|NULLOK SV* val|U32 hash
Ap |void |hv_free_ent |NN HV* hv|NULLOK HE* entryK
Apd |I32 |hv_iterinit |NN HV* tb
ApdR |char* |hv_iterkey |NN HE* entry|NN I32* retlen
Expand Down Expand Up @@ -1145,8 +1148,6 @@ rs |void |hv_notallowed |int flags|NN const char *key|I32 klen|NN const char *ms
sn |struct xpvhv_aux*|hv_auxinit|NN HV *hv
sM |SV* |hv_delete_common|NULLOK HV* tb|NULLOK SV* keysv|NULLOK const char* key \
|STRLEN klen|int k_flags|I32 d_flags|U32 hash
sM |HE* |hv_fetch_common|NULLOK HV* tb|NULLOK SV* keysv|NULLOK const char* key \
|STRLEN klen|int flags|int action|NULLOK SV* val|U32 hash
sM |void |clear_placeholders |NN HV* hb|U32 items
sM |SV * |refcounted_he_value |NN const struct refcounted_he *he
#endif
Expand Down
4 changes: 2 additions & 2 deletions embed.h
Expand Up @@ -285,6 +285,7 @@
#define hv_exists_ent Perl_hv_exists_ent
#define hv_fetch Perl_hv_fetch
#define hv_fetch_ent Perl_hv_fetch_ent
#define hv_common Perl_hv_common
#define hv_free_ent Perl_hv_free_ent
#define hv_iterinit Perl_hv_iterinit
#define hv_iterkey Perl_hv_iterkey
Expand Down Expand Up @@ -1145,7 +1146,6 @@
#define hv_notallowed S_hv_notallowed
#define hv_auxinit S_hv_auxinit
#define hv_delete_common S_hv_delete_common
#define hv_fetch_common S_hv_fetch_common
#define clear_placeholders S_clear_placeholders
#define refcounted_he_value S_refcounted_he_value
#endif
Expand Down Expand Up @@ -2570,6 +2570,7 @@
#define hv_exists_ent(a,b,c) Perl_hv_exists_ent(aTHX_ a,b,c)
#define hv_fetch(a,b,c,d) Perl_hv_fetch(aTHX_ a,b,c,d)
#define hv_fetch_ent(a,b,c,d) Perl_hv_fetch_ent(aTHX_ a,b,c,d)
#define hv_common(a,b,c,d,e,f,g,h) Perl_hv_common(aTHX_ a,b,c,d,e,f,g,h)
#define hv_free_ent(a,b) Perl_hv_free_ent(aTHX_ a,b)
#define hv_iterinit(a) Perl_hv_iterinit(aTHX_ a)
#define hv_iterkey(a,b) Perl_hv_iterkey(aTHX_ a,b)
Expand Down Expand Up @@ -3425,7 +3426,6 @@
#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)
#define hv_fetch_common(a,b,c,d,e,f,g,h) S_hv_fetch_common(aTHX_ a,b,c,d,e,f,g,h)
#define clear_placeholders(a,b) S_clear_placeholders(aTHX_ a,b)
#define refcounted_he_value(a) S_refcounted_he_value(aTHX_ a)
#endif
Expand Down
75 changes: 36 additions & 39 deletions hv.c
Expand Up @@ -253,8 +253,8 @@ Perl_hv_store(pTHX_ HV *hv, const char *key, I32 klen_i32, SV *val, U32 hash)
klen = klen_i32;
flags = 0;
}
hek = hv_fetch_common (hv, NULL, key, klen, flags,
(HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
hek = hv_common(hv, NULL, key, klen, flags,
(HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
return hek ? &HeVAL(hek) : NULL;
}

Expand All @@ -263,7 +263,7 @@ SV**
Perl_hv_store_flags(pTHX_ HV *hv, const char *key, I32 klen, SV *val,
register U32 hash, int flags)
{
HE * const hek = hv_fetch_common (hv, NULL, key, klen, flags,
HE * const hek = hv_common(hv, NULL, key, klen, flags,
(HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
return hek ? &HeVAL(hek) : NULL;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ information on how to use this function on tied hashes.
HE *
Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, U32 hash)
{
return hv_fetch_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
return hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
}

/*
Expand All @@ -326,7 +326,7 @@ Perl_hv_exists(pTHX_ HV *hv, const char *key, I32 klen_i32)
klen = klen_i32;
flags = 0;
}
return hv_fetch_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0)
return hv_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0)
? TRUE : FALSE;
}

Expand Down Expand Up @@ -358,9 +358,9 @@ Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
klen = klen_i32;
flags = 0;
}
hek = hv_fetch_common (hv, NULL, key, klen, flags,
lval ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE) : HV_FETCH_JUST_SV,
NULL, 0);
hek = hv_common(hv, NULL, key, klen, flags, lval
? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE) : HV_FETCH_JUST_SV,
NULL, 0);
return hek ? &HeVAL(hek) : NULL;
}

Expand All @@ -378,7 +378,7 @@ computed.
bool
Perl_hv_exists_ent(pTHX_ HV *hv, SV *keysv, U32 hash)
{
return hv_fetch_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash)
return hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash)
? TRUE : FALSE;
}

Expand All @@ -404,13 +404,13 @@ information on how to use this function on tied hashes.
HE *
Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, register U32 hash)
{
return hv_fetch_common(hv, keysv, NULL, 0, 0,
(lval ? HV_FETCH_LVALUE : 0), NULL, hash);
return hv_common(hv, keysv, NULL, 0, 0,
(lval ? HV_FETCH_LVALUE : 0), NULL, hash);
}

STATIC HE *
S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
int flags, int action, SV *val, register U32 hash)
HE *
Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
int flags, int action, SV *val, register U32 hash)
{
dVAR;
XPVHV* xhv;
Expand Down Expand Up @@ -516,21 +516,21 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
const char * const nkey = strupr(savepvn(key,klen));
/* Note that this fetch is for nkey (the uppercased
key) whereas the store is for key (the original) */
entry = hv_fetch_common(hv, NULL, nkey, klen,
HVhek_FREEKEY, /* free nkey */
0 /* non-LVAL fetch */
| HV_DISABLE_UVAR_XKEY,
NULL /* no value */,
0 /* compute hash */);
entry = hv_common(hv, NULL, nkey, klen,
HVhek_FREEKEY, /* free nkey */
0 /* non-LVAL fetch */
| HV_DISABLE_UVAR_XKEY,
NULL /* no value */,
0 /* compute hash */);
if (!entry && (action & HV_FETCH_LVALUE)) {
/* This call will free key if necessary.
Do it this way to encourage compiler to tail
call optimise. */
entry = hv_fetch_common(hv, keysv, key, klen,
flags,
HV_FETCH_ISSTORE
| HV_DISABLE_UVAR_XKEY,
newSV(0), hash);
entry = hv_common(hv, keysv, key, klen,
flags,
HV_FETCH_ISSTORE
| HV_DISABLE_UVAR_XKEY,
newSV(0), hash);
} else {
if (flags & HVhek_FREEKEY)
Safefree(key);
Expand Down Expand Up @@ -779,9 +779,8 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
if (env) {
sv = newSVpvn(env,len);
SvTAINTED_on(sv);
return hv_fetch_common(hv, keysv, key, klen, flags,
HV_FETCH_ISSTORE|HV_DISABLE_UVAR_XKEY, sv,
hash);
return hv_common(hv, keysv, key, klen, flags,
HV_FETCH_ISSTORE|HV_DISABLE_UVAR_XKEY, sv, hash);
}
}
#endif
Expand Down Expand Up @@ -810,9 +809,8 @@ S_hv_fetch_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
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);
return hv_common(hv, keysv, key, klen, flags,
HV_FETCH_ISSTORE|HV_DISABLE_UVAR_XKEY, val, hash);
/* XXX Surely that could leak if the fetch-was-store fails?
Just like the hv_fetch. */
}
Expand Down Expand Up @@ -957,8 +955,8 @@ Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
klen = klen_i32;
k_flags = 0;
}
return (SV *) hv_fetch_common(hv, NULL, key, klen, k_flags,
flags | HV_DELETE, NULL, 0);
return (SV *) hv_common(hv, NULL, key, klen, k_flags, flags | HV_DELETE,
NULL, 0);
}

/*
Expand All @@ -976,8 +974,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 (SV *) hv_fetch_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE,
NULL, hash);
return (SV *) hv_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, NULL,
hash);
}

STATIC SV *
Expand All @@ -999,10 +997,9 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,

if (needs_copy) {
SV *sv;
entry = hv_fetch_common(hv, keysv, key, klen,
k_flags & ~HVhek_FREEKEY,
HV_FETCH_LVALUE|HV_DISABLE_UVAR_XKEY,
NULL, hash);
entry = hv_common(hv, keysv, key, klen, k_flags & ~HVhek_FREEKEY,
HV_FETCH_LVALUE|HV_DISABLE_UVAR_XKEY, NULL,
hash);
sv = entry ? HeVAL(entry) : NULL;
if (sv) {
if (SvMAGICAL(sv)) {
Expand Down
2 changes: 1 addition & 1 deletion proto.h
Expand Up @@ -704,6 +704,7 @@ PERL_CALLCONV SV** Perl_hv_fetch(pTHX_ HV* tb, const char* key, I32 klen, I32 lv
PERL_CALLCONV HE* Perl_hv_fetch_ent(pTHX_ HV* tb, SV* key, I32 lval, U32 hash)
__attribute__nonnull__(pTHX_2);

PERL_CALLCONV HE* Perl_hv_common(pTHX_ HV* tb, SV* keysv, const char* key, STRLEN klen, int flags, int action, SV* val, U32 hash);
PERL_CALLCONV void Perl_hv_free_ent(pTHX_ HV* hv, HE* entryK)
__attribute__nonnull__(pTHX_1);

Expand Down Expand Up @@ -3053,7 +3054,6 @@ STATIC struct xpvhv_aux* S_hv_auxinit(HV *hv)
__attribute__nonnull__(1);

STATIC SV* S_hv_delete_common(pTHX_ HV* tb, SV* keysv, const char* key, STRLEN klen, int k_flags, I32 d_flags, U32 hash);
STATIC HE* S_hv_fetch_common(pTHX_ HV* tb, SV* keysv, const char* key, STRLEN klen, int flags, int action, SV* val, U32 hash);
STATIC void S_clear_placeholders(pTHX_ HV* hb, U32 items)
__attribute__nonnull__(pTHX_1);

Expand Down

0 comments on commit d3ba3f5

Please sign in to comment.