Skip to content

Commit

Permalink
Use HvTOTALKEYS() in place of HvARRAY() in various boolean tests
Browse files Browse the repository at this point in the history
This is a better choice for an "is it empty?" optimisation, as HvARRAY()
can be non-NULL even when there actually are no keys.
  • Loading branch information
nwc10 committed Sep 3, 2021
1 parent 8937088 commit ec7598c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions dump.c
Expand Up @@ -686,7 +686,7 @@ Perl_dump_packsubs_perl(pTHX_ const HV *stash, bool justperl)

PERL_ARGS_ASSERT_DUMP_PACKSUBS_PERL;

if (!HvARRAY(stash))
if (!HvTOTALKEYS(stash))
return;
for (i = 0; i <= (I32) HvMAX(stash); i++) {
const HE *entry;
Expand Down Expand Up @@ -2207,12 +2207,12 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
}
if (nest < maxnest) {
HV * const hv = MUTABLE_HV(sv);
STRLEN i;
HE *he;

if (HvARRAY(hv)) {
if (HvTOTALKEYS(hv)) {
STRLEN i;
int count = maxnest - nest;
for (i=0; i <= HvMAX(hv); i++) {
HE *he;
for (he = HvARRAY(hv)[i]; he; he = HeNEXT(he)) {
U32 hash;
SV * keysv;
Expand Down
4 changes: 2 additions & 2 deletions hv.c
Expand Up @@ -1164,7 +1164,7 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
}
}
xhv = (XPVHV*)SvANY(hv);
if (!HvARRAY(hv))
if (!HvTOTALKEYS(hv))
return NULL;

if (is_utf8 && !(k_flags & HVhek_KEYCANONICAL)) {
Expand Down Expand Up @@ -1809,7 +1809,7 @@ Perl_hv_clear(pTHX_ HV *hv)
EXTEND_MORTAL(1);
PL_tmps_stack[++PL_tmps_ix] = SvREFCNT_inc_simple_NN(hv);
orig_ix = PL_tmps_ix;
if (SvREADONLY(hv) && HvARRAY(hv) != NULL) {
if (SvREADONLY(hv) && HvTOTALKEYS(hv)) {
/* restricted hash: convert all keys to placeholders */
STRLEN i;
for (i = 0; i <= xhv->xhv_max; i++) {
Expand Down
4 changes: 2 additions & 2 deletions sv.c
Expand Up @@ -9905,7 +9905,7 @@ Perl_sv_resetpvn(pTHX_ const char *s, STRLEN len, HV * const stash)

/* reset variables */

if (!HvARRAY(stash))
if (!HvTOTALKEYS(stash))
return;

Zero(todo, 256, char);
Expand Down Expand Up @@ -16235,7 +16235,7 @@ S_find_hash_subscript(pTHX_ const HV *const hv, const SV *const val)

PERL_ARGS_ASSERT_FIND_HASH_SUBSCRIPT;

if (!hv || SvMAGICAL(hv) || !HvARRAY(hv) ||
if (!hv || SvMAGICAL(hv) || !HvTOTALKEYS(hv) ||
(HvTOTALKEYS(hv) > FUV_MAX_SEARCH_SIZE))
return NULL;

Expand Down

0 comments on commit ec7598c

Please sign in to comment.