summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-08-22 08:35:30 +0000
committerNicholas Clark <nick@ccl4.org>2021-08-23 08:29:09 +0000
commite2737abbb702a05e83f4aa2486a941ac3964446a (patch)
tree08bd941b725574c8755d7906889bebad14a88670 /pp_hot.c
parent77745d701ca519f67def45b50e91f34685ee92e3 (diff)
downloadperl-e2737abbb702a05e83f4aa2486a941ac3964446a.tar.gz
Pre-extend hashes in list assignment before assigning to them.
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.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 6e7e384f18..17683ff000 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -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;