Skip to content

Commit

Permalink
Pre-extend hashes in list assignment before assigning to them.
Browse files Browse the repository at this point in the history
We know how many pairs of keys/values are on the stack, so pre-extend the
hash to the appropriate size, instead of letting the hash needlessly re-size
one or more times during the assignment loop.
  • Loading branch information
nwc10 committed Aug 23, 2021
1 parent 77745d7 commit e2737ab
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pp_hot.c
Expand Up @@ -2571,6 +2571,11 @@ PP(pp_aassign)
if (SvRMAGICAL(hash) || HvUSEDKEYS(hash))
hv_clear(hash);

/* "nelems" was converted to the number of pairs earlier. */
if (nelems > PERL_HASH_DEFAULT_HvMAX) {
hv_ksplit(hash, nelems);
}

/* now assign the keys and values to the hash */

dirty_tmps = FALSE;
Expand Down

0 comments on commit e2737ab

Please sign in to comment.