Skip to content

Commit

Permalink
Convert code in mro_core.c to use hv_*hek() APIs where possible.
Browse files Browse the repository at this point in the history
Add a macro hv_existshek() to implement exists.

The HEK-based macros are more efficient wrappers of hv_common() than the
string/length/flags macros because they also pass in the pre-computed hash
value (from the HEK). This avoids hv_common() needing to recalculate it.
  • Loading branch information
nwc10 committed Jul 26, 2021
1 parent bffed14 commit 5ebe3ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions hv.h
Expand Up @@ -533,6 +533,9 @@ See L</hv_fill>.
# define hv_deletehek(hv, hek, flags) \
hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \
(flags)|HV_DELETE, NULL, HEK_HASH(hek))
#define hv_existshek(hv, hek) \
cBOOL(hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \
HV_FETCH_ISEXISTS, NULL, HEK_HASH(hek)))
#endif

/* This refcounted he structure is used for storing the hints used for lexical
Expand Down
16 changes: 7 additions & 9 deletions mro_core.c
Expand Up @@ -697,18 +697,16 @@ S_mro_clean_isarev(pTHX_ HV * const isa, const char * const name,
if(HvARRAY(isa) && hv_iterinit(isa)) {
SV **svp;
while((iter = hv_iternext(isa))) {
I32 klen;
const char * const key = hv_iterkey(iter, &klen);
if(exceptions && hv_exists(exceptions, key, HeKUTF8(iter) ? -klen : klen))
HEK *key = HeKEY_hek(iter);
if(exceptions && hv_existshek(exceptions, key))
continue;
svp = hv_fetch(PL_isarev, key, HeKUTF8(iter) ? -klen : klen, 0);
svp = hv_fetchhek(PL_isarev, key, 0);
if(svp) {
HV * const isarev = (HV *)*svp;
(void)hv_common(isarev, NULL, name, len, flags,
G_DISCARD|HV_DELETE, NULL, hash);
if(!HvARRAY(isarev) || !HvUSEDKEYS(isarev))
(void)hv_delete(PL_isarev, key,
HeKUTF8(iter) ? -klen : klen, G_DISCARD);
(void)hv_deletehek(PL_isarev, key, G_DISCARD);
}
}
}
Expand Down Expand Up @@ -1137,7 +1135,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
|| (len == 1 && key[0] == ':')) {
HV * const oldsubstash = GvHV(HeVAL(entry));
SV ** const stashentry
= stash ? hv_fetch(stash, key, HeUTF8(entry) ? -(I32)len : (I32)len, 0) : NULL;
= stash ? hv_fetchhek(stash, HeKEY_hek(entry), 0) : NULL;
HV *substash = NULL;

/* Avoid main::main::main::... */
Expand Down Expand Up @@ -1191,7 +1189,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
);
}

(void)hv_store(seen, key, HeUTF8(entry) ? -(I32)len : (I32)len, &PL_sv_yes, 0);
(void)hv_storehek(seen, HeKEY_hek(entry), &PL_sv_yes);
}
}
}
Expand Down Expand Up @@ -1223,7 +1221,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,

/* If this entry was seen when we iterated through the
oldstash, skip it. */
if(seen && hv_exists(seen, key, HeUTF8(entry) ? -(I32)len : (I32)len)) continue;
if(seen && hv_existshek(seen, HeKEY_hek(entry))) continue;

/* We get here only if this stash has no corresponding
entry in the stash being replaced. */
Expand Down

0 comments on commit 5ebe3ee

Please sign in to comment.