dVAR;
HE* he;
HE* heend;
- Newx(he, PERL_ARENA_SIZE/sizeof(HE), HE);
- HeNEXT(he) = (HE*) PL_body_arenaroots[HE_SVSLOT];
- PL_body_arenaroots[HE_SVSLOT] = he;
+
+ he = (HE*) Perl_get_arena(aTHX_ PERL_ARENA_SIZE);
+ HeNEXT(he) = (HE*) PL_body_arenas;
+ PL_body_arenas = he;
heend = &he[PERL_ARENA_SIZE / sizeof(HE) - 1];
PL_body_roots[HE_SVSLOT] = ++he;
}
hek = hv_fetch_common (hv, NULL, key, klen, flags,
lval ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE) : HV_FETCH_JUST_SV,
- Nullsv, 0);
+ NULL, 0);
return hek ? &HeVAL(hek) : NULL;
}
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), Nullsv, hash);
+ (lval ? HV_FETCH_LVALUE : 0), NULL, hash);
}
STATIC HE *
xhv = (XPVHV*)SvANY(hv);
if (SvMAGICAL(hv)) {
- if (SvRMAGICAL(hv) && !(action & (HV_FETCH_ISSTORE|HV_FETCH_ISEXISTS)))
- {
+ if (SvRMAGICAL(hv) && !(action & (HV_FETCH_ISSTORE|HV_FETCH_ISEXISTS))) {
if (mg_find((SV*)hv, PERL_MAGIC_tied) || SvGMAGICAL((SV*)hv)) {
sv = sv_newmortal();
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, Nullsv, nkey, klen,
+ entry = hv_fetch_common(hv, NULL, nkey, klen,
HVhek_FREEKEY, /* free nkey */
0 /* non-LVAL fetch */,
- Nullsv /* no value */,
+ NULL /* no value */,
0 /* compute hash */);
if (!entry && (action & HV_FETCH_LVALUE)) {
/* This call will free key if necessary.
call optimise. */
entry = hv_fetch_common(hv, keysv, key, klen,
flags, HV_FETCH_ISSTORE,
- NEWSV(61,0), hash);
+ newSV(0), hash);
} else {
if (flags & HVhek_FREEKEY)
Safefree(key);
/* Will need to free this, so set FREEKEY flag. */
key = savepvn(key,klen);
key = (const char*)strupr((char*)key);
- is_utf8 = 0;
+ is_utf8 = FALSE;
hash = 0;
keysv = 0;
/* Will need to free this, so set FREEKEY flag. */
key = savepvn(key,klen);
key = (const char*)strupr((char*)key);
- is_utf8 = 0;
+ is_utf8 = FALSE;
hash = 0;
keysv = 0;
}
if (is_utf8) {
- char * const keysave = (char * const)key;
+ char * const keysave = (char *)key;
key = (char*)bytes_from_utf8((U8*)key, &klen, &is_utf8);
if (is_utf8)
flags |= HVhek_UTF8;
/* Need to swap the key we have for a key with the flags we
need. As keys are shared we can't just write to the
flag, so we share the new one, unshare the old one. */
- HEK *new_hek = share_hek_flags(key, klen, hash,
+ HEK * const new_hek = share_hek_flags(key, klen, hash,
masked_flags);
unshare_hek (HeKEY_hek(entry));
HeKEY_hek(entry) = new_hek;
break;
}
/* LVAL fetch which actaully needs a store. */
- val = NEWSV(61,0);
+ val = newSV(0);
HvPLACEHOLDERS(hv)--;
} else {
/* store */
return 0;
}
if (action & HV_FETCH_LVALUE) {
- val = NEWSV(61,0);
+ val = newSV(0);
if (SvMAGICAL(hv)) {
/* At this point the old hv_fetch code would call to hv_store,
which in turn might do some tied magic. So we need to make that
Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
{
STRLEN klen;
- int k_flags = 0;
+ int k_flags;
if (klen_i32 < 0) {
klen = -klen_i32;
- k_flags |= HVhek_UTF8;
+ k_flags = HVhek_UTF8;
} else {
klen = klen_i32;
+ k_flags = 0;
}
return hv_delete_common(hv, NULL, key, klen, k_flags, flags, 0);
}
register HE *entry;
register HE **oentry;
HE *const *first_entry;
- SV *sv;
bool is_utf8;
int masked_flags;
if (!hv)
- return Nullsv;
+ return NULL;
if (keysv) {
if (k_flags & HVhek_FREEKEY)
hv_magic_check (hv, &needs_copy, &needs_store);
if (needs_copy) {
+ SV *sv;
entry = hv_fetch_common(hv, keysv, key, klen,
k_flags & ~HVhek_FREEKEY, HV_FETCH_LVALUE,
- Nullsv, hash);
+ NULL, hash);
sv = entry ? HeVAL(entry) : NULL;
if (sv) {
if (SvMAGICAL(sv)) {
sv_unmagic(sv, PERL_MAGIC_tiedelem);
return sv;
}
- return Nullsv; /* element cannot be deleted */
+ return NULL; /* element cannot be deleted */
}
#ifdef ENV_IS_CASELESS
else if (mg_find((SV*)hv, PERL_MAGIC_env)) {
}
xhv = (XPVHV*)SvANY(hv);
if (!HvARRAY(hv))
- return Nullsv;
+ return NULL;
if (is_utf8) {
const char * const keysave = key;
first_entry = oentry = &(HvARRAY(hv))[hash & (I32) HvMAX(hv)];
entry = *oentry;
for (; entry; oentry = &HeNEXT(entry), entry = *oentry) {
+ SV *sv;
if (HeHASH(entry) != hash) /* strings can't be equal */
continue;
if (HeKLEN(entry) != (I32)klen)
}
/* if placeholder is here, it's already been deleted.... */
- if (HeVAL(entry) == &PL_sv_placeholder)
- {
- if (k_flags & HVhek_FREEKEY)
- Safefree(key);
- return Nullsv;
+ if (HeVAL(entry) == &PL_sv_placeholder) {
+ if (k_flags & HVhek_FREEKEY)
+ Safefree(key);
+ return NULL;
}
- else if (SvREADONLY(hv) && HeVAL(entry) && SvREADONLY(HeVAL(entry))) {
+ if (SvREADONLY(hv) && HeVAL(entry) && SvREADONLY(HeVAL(entry))) {
S_hv_notallowed(aTHX_ k_flags, key, klen,
"Attempt to delete readonly key '%"SVf"' from"
" a restricted hash");
Safefree(key);
if (d_flags & G_DISCARD)
- sv = Nullsv;
+ sv = NULL;
else {
sv = sv_2mortal(HeVAL(entry));
HeVAL(entry) = &PL_sv_placeholder;
if (k_flags & HVhek_FREEKEY)
Safefree(key);
- return Nullsv;
+ return NULL;
}
STATIC void
if (!*aep) /* non-existent */
continue;
for (oentry = aep, entry = *aep; entry; entry = *oentry) {
- register I32 j;
- if ((j = (HeHASH(entry) & newsize)) != i) {
+ register I32 j = (HeHASH(entry) & newsize);
+
+ if (j != i) {
j -= i;
*oentry = HeNEXT(entry);
if (!(HeNEXT(entry) = aep[j]))
Perl_newHV(pTHX)
{
register XPVHV* xhv;
- HV * const hv = (HV*)NEWSV(502,0);
+ HV * const hv = (HV*)newSV(0);
sv_upgrade((SV *)hv, SVt_PVHV);
xhv = (XPVHV*)SvANY(hv);
/* In each bucket... */
for (i = 0; i <= hv_max; i++) {
- HE *prev = NULL, *ent = NULL;
+ HE *prev = NULL;
HE *oent = oents[i];
if (!oent) {
const char * const key = HeKEY(oent);
const STRLEN len = HeKLEN(oent);
const int flags = HeKFLAGS(oent);
+ HE * const ent = new_HE();
- ent = new_HE();
HeVAL(ent) = newSVsv(HeVAL(oent));
HeKEY_hek(ent)
= shared ? share_hek_flags(key, len, hash, flags)
/* not already placeholder */
if (HeVAL(entry) != &PL_sv_placeholder) {
if (HeVAL(entry) && SvREADONLY(HeVAL(entry))) {
- SV* keysv = hv_iterkeysv(entry);
+ SV* const keysv = hv_iterkeysv(entry);
Perl_croak(aTHX_
"Attempt to delete readonly key '%"SVf"' from a restricted hash",
keysv);
i = HvMAX(hv);
do {
/* Loop down the linked list heads */
- bool first = 1;
+ bool first = TRUE;
HE **oentry = &(HvARRAY(hv))[i];
HE *entry;
}
} else {
oentry = &HeNEXT(entry);
- first = 0;
+ first = FALSE;
}
}
} while (--i >= 0);
/* This is the one we're going to try to empty. First time round
it's the original array. (Hopefully there will only be 1 time
round) */
- HE **array = HvARRAY(hv);
+ HE ** const array = HvARRAY(hv);
I32 i = HvMAX(hv);
/* Because we have taken xhv_name out, the only allocated pointer
if (--attempts == 0) {
Perl_die(aTHX_ "panic: hfreeentries failed to free hash - something is repeatedly re-creating entries");
}
- };
+ }
HvARRAY(hv) = orig_array;
if ((name = HvNAME_get(hv))) {
if(PL_stashcache)
hv_delete(PL_stashcache, name, HvNAMELEN_get(hv), G_DISCARD);
- hv_name_set(hv, Nullch, 0, 0);
+ hv_name_set(hv, NULL, 0, 0);
}
SvFLAGS(hv) &= ~SVf_OOK;
Safefree(HvARRAY(hv));
Perl_croak(aTHX_ "Bad hash");
if (SvOOK(hv)) {
- struct xpvhv_aux *iter = HvAUX(hv);
+ struct xpvhv_aux * const iter = HvAUX(hv);
HE * const entry = iter->xhv_eiter; /* HvEITER(hv) */
if (entry && HvLAZYDEL(hv)) { /* was deleted earlier? */
HvLAZYDEL_off(hv);
iter->xhv_riter = -1; /* HvRITER(hv) = -1 */
iter->xhv_eiter = Null(HE*); /* HvEITER(hv) = Null(HE*) */
} else {
- S_hv_auxinit(aTHX_ hv);
+ hv_auxinit(hv);
}
/* used to be xhv->xhv_fill before 5.004_65 */
if (!hv)
Perl_croak(aTHX_ "Bad hash");
- iter = SvOOK(hv) ? HvAUX(hv) : S_hv_auxinit(aTHX_ hv);
+ iter = SvOOK(hv) ? HvAUX(hv) : hv_auxinit(hv);
return &(iter->xhv_riter);
}
if (!hv)
Perl_croak(aTHX_ "Bad hash");
- iter = SvOOK(hv) ? HvAUX(hv) : S_hv_auxinit(aTHX_ hv);
+ iter = SvOOK(hv) ? HvAUX(hv) : hv_auxinit(hv);
return &(iter->xhv_eiter);
}
if (riter == -1)
return;
- iter = S_hv_auxinit(aTHX_ hv);
+ iter = hv_auxinit(hv);
}
iter->xhv_riter = riter;
}
if (!eiter)
return;
- iter = S_hv_auxinit(aTHX_ hv);
+ iter = hv_auxinit(hv);
}
iter->xhv_eiter = eiter;
}
if (name == 0)
return;
- iter = S_hv_auxinit(aTHX_ hv);
+ iter = hv_auxinit(hv);
}
PERL_HASH(hash, name, len);
iter->xhv_name = name ? share_hek(name, len, hash) : 0;
AV **
Perl_hv_backreferences_p(pTHX_ HV *hv) {
- struct xpvhv_aux *iter;
-
- iter = SvOOK(hv) ? HvAUX(hv) : S_hv_auxinit(aTHX_ hv);
+ struct xpvhv_aux * const iter = SvOOK(hv) ? HvAUX(hv) : hv_auxinit(hv);
return &(iter->xhv_backreferences);
}
assert (he->shared_he_he.hent_hek == hek);
LOCK_STRTAB_MUTEX;
- if (he->shared_he_he.hent_val - 1) {
- --he->shared_he_he.hent_val;
+ if (he->shared_he_he.he_valu.hent_refcount - 1) {
+ --he->shared_he_he.he_valu.hent_refcount;
UNLOCK_STRTAB_MUTEX;
return;
}
k_flags |= HVhek_WASUTF8 | HVhek_FREEKEY;
}
- /* what follows is the moral equivalent of:
+ /* what follows was the moral equivalent of:
if ((Svp = hv_fetch(PL_strtab, tmpsv, FALSE, hash))) {
- if (--*Svp == Nullsv)
+ if (--*Svp == NULL)
hv_delete(PL_strtab, str, len, G_DISCARD, hash);
} */
xhv = (XPVHV*)SvANY(PL_strtab);
}
if (found) {
- if (--HeVAL(entry) == Nullsv) {
+ if (--he->shared_he_he.he_valu.hent_refcount == 0) {
*oentry = HeNEXT(entry);
if (!*first) {
/* There are now no entries in our slot. */
/* what follows is the moral equivalent of:
if (!(Svp = hv_fetch(PL_strtab, str, len, FALSE)))
- hv_store(PL_strtab, str, len, Nullsv, hash);
+ hv_store(PL_strtab, str, len, NULL, hash);
Can't rehash the shared string table, so not sure if it's worth
counting the number of entries in the linked list
/* Still "point" to the HEK, so that other code need not know what
we're up to. */
HeKEY_hek(entry) = hek;
- HeVAL(entry) = Nullsv;
+ entry->he_valu.hent_refcount = 0;
HeNEXT(entry) = next;
*head = entry;
}
}
- ++HeVAL(entry); /* use value slot as REFCNT */
+ ++entry->he_valu.hent_refcount;
UNLOCK_STRTAB_MUTEX;
if (flags & HVhek_FREEKEY)