summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-05-26 14:24:31 +0000
committerNicholas Clark <nick@ccl4.org>2005-05-26 14:24:31 +0000
commit7423f6db106ad471398838e82e73b22d8c1e166e (patch)
treeab25b2b670e12e8d4ae54af8c7e216c47ef20c4a /hv.c
parentc4a9c09d5b30a93b6241aff3c9915e33e4e41eeb (diff)
downloadperl-7423f6db106ad471398838e82e73b22d8c1e166e.tar.gz
Store the package name as a shared HEK.
Abolish HvNAME() - as the stored pointer is not a char* you can't set it directly now. Storing a pointer to a HEK tracks the length too, and seems to be faster. p4raw-id: //depot/perl@24584
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/hv.c b/hv.c
index 5086b83a92..fe7e3885c6 100644
--- a/hv.c
+++ b/hv.c
@@ -1627,7 +1627,8 @@ S_hfreeentries(pTHX_ HV *hv)
HvLAZYDEL_off(hv);
hv_free_ent(hv, entry);
}
- Safefree(iter->xhv_name);
+ if (iter->xhv_name)
+ unshare_hek_or_pvn(iter->xhv_name, 0, 0, 0);
Safefree(iter);
((XPVHV*) SvANY(hv))->xhv_aux = 0;
}
@@ -1653,9 +1654,8 @@ Perl_hv_undef(pTHX_ HV *hv)
hfreeentries(hv);
Safefree(HvARRAY(hv));
if ((name = HvNAME_get(hv))) {
- /* FIXME - strlen HvNAME */
if(PL_stashcache)
- hv_delete(PL_stashcache, name, strlen(name), G_DISCARD);
+ hv_delete(PL_stashcache, name, HvNAMELEN_get(hv), G_DISCARD);
Perl_hv_name_set(aTHX_ hv, 0, 0, 0);
}
xhv->xhv_max = 7; /* HvMAX(hv) = 7 (it's a normal hash) */
@@ -1787,32 +1787,24 @@ Perl_hv_eiter_set(pTHX_ HV *hv, HE *eiter) {
iter->xhv_eiter = eiter;
}
-
-char **
-Perl_hv_name_p(pTHX_ HV *hv)
-{
- struct xpvhv_aux *iter = ((XPVHV *)SvANY(hv))->xhv_aux;
-
- if (!iter) {
- ((XPVHV *)SvANY(hv))->xhv_aux = iter = S_hv_auxinit(aTHX);
- }
- return &(iter->xhv_name);
-}
-
void
-Perl_hv_name_set(pTHX_ HV *hv, const char *name, STRLEN len, int flags)
+Perl_hv_name_set(pTHX_ HV *hv, const char *name, I32 len, int flags)
{
struct xpvhv_aux *iter = ((XPVHV *)SvANY(hv))->xhv_aux;
+ U32 hash;
if (iter) {
- Safefree(iter->xhv_name);
+ if (iter->xhv_name) {
+ unshare_hek_or_pvn(iter->xhv_name, 0, 0, 0);
+ }
} else {
if (name == 0)
return;
((XPVHV *)SvANY(hv))->xhv_aux = iter = S_hv_auxinit(aTHX);
}
- iter->xhv_name = savepvn(name, len);
+ PERL_HASH(hash, name, len);
+ iter->xhv_name = name ? share_hek(name, len, hash) : 0;
}
/*