From 5ebe3ee8a2e8df14624495256026a546dbf8c1dc Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 20 Jul 2021 20:05:44 +0000 Subject: [PATCH] Convert code in mro_core.c to use hv_*hek() APIs where possible. 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. --- hv.h | 3 +++ mro_core.c | 16 +++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hv.h b/hv.h index 119cf8c9662d..a43b9611bbf1 100644 --- a/hv.h +++ b/hv.h @@ -533,6 +533,9 @@ See L. # 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 diff --git a/mro_core.c b/mro_core.c index bb513df8cd29..8e8ed3bac0ee 100644 --- a/mro_core.c +++ b/mro_core.c @@ -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); } } } @@ -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::... */ @@ -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); } } } @@ -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. */