diff options
author | Nicholas Clark <nick@ccl4.org> | 2021-11-10 10:57:34 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2021-12-18 17:54:34 +0000 |
commit | 5d73aca10c2e46b1f9ea1687f0f3e1a95a489653 (patch) | |
tree | 594f2fa957275e3f55f052a60ff3cfaa9bb6177b | |
parent | 7ab3ff6e3556756a0cabd4d4079485903f1aaabe (diff) | |
download | perl-5d73aca10c2e46b1f9ea1687f0f3e1a95a489653.tar.gz |
No need to Renew() HvARRAY() to the same size in S_hv_auxinit()
Fix a thinko/missed simplification that should have been part of
commit 53a41f9c2c0671d8:
Inline the xhv_aux struct in the main hash body
For now, memory for this structure is always allocated, even though it
isn't always flagged as being present.
Prior to that commit the Renew() in S_hv_auxinit() had been needed because
the memory that HvARRAY() points to needed to be expanded from "just the
array of HE pointers" to "that, plus space for the xhv_aux struct.
With that commit, the xhv_aux struct was no longer stored in the same
memory block, so there was no need to reallocate storage. Hence the
Renew() should be completely removed. What that commit actually did was
neatly change the parameters to the Renew() call such that it reallocated
storage to the exact same size, which isn't wrong, but is makework. Oops.
-rw-r--r-- | hv.c | 9 |
1 files changed, 3 insertions, 6 deletions
@@ -2231,18 +2231,15 @@ PERL_STATIC_INLINE U32 S_ptr_hash(PTRV u) { static struct xpvhv_aux* S_hv_auxinit(pTHX_ HV *hv) { struct xpvhv_aux *iter; - char *array; PERL_ARGS_ASSERT_HV_AUXINIT; if (!SvOOK(hv)) { - if (!HvARRAY(hv)) { + char *array = (char *) HvARRAY(hv); + if (!array) { Newxz(array, PERL_HV_ARRAY_ALLOC_BYTES(HvMAX(hv) + 1), char); - } else { - array = (char *) HvARRAY(hv); - Renew(array, PERL_HV_ARRAY_ALLOC_BYTES(HvMAX(hv) + 1), char); + HvARRAY(hv) = (HE**)array; } - HvARRAY(hv) = (HE**)array; iter = Perl_hv_auxalloc(aTHX_ hv); #ifdef PERL_HASH_RANDOMIZE_KEYS if (PL_HASH_RAND_BITS_ENABLED) { |