diff options
author | Nicholas Clark <nick@ccl4.org> | 2021-10-17 08:41:19 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2021-10-20 15:34:23 +0000 |
commit | a31d0367bbf1e97bab6eece95b47ca513e1834a6 (patch) | |
tree | fb693180f93306dc9d033d4dfd6a5aa110cca9f9 /hv.c | |
parent | 33042aafe7427f88db58e555390c82dd25ef9a28 (diff) | |
download | perl-a31d0367bbf1e97bab6eece95b47ca513e1834a6.tar.gz |
Perl_newHVhv should use share_hek_hek() instead of share_hek_flags()
share_hek_hek() manipulates the shared HEK's reference count directly,
without needing to find it in the shared string table. It was added after
Perl_newHVhv() was implemented, and no-one noticed that it could be used
there.
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -1620,17 +1620,20 @@ Perl_newHVhv(pTHX_ HV *ohv) /* Copy the linked list of entries. */ for (; oent; oent = HeNEXT(oent)) { - const U32 hash = HeHASH(oent); - const char * const key = HeKEY(oent); - const STRLEN len = HeKLEN(oent); - const int flags = HeKFLAGS(oent); HE * const ent = new_HE(); SV *const val = HeVAL(oent); HeVAL(ent) = SvIMMORTAL(val) ? val : newSVsv(val); - HeKEY_hek(ent) - = shared ? share_hek_flags(key, len, hash, flags) - : save_hek_flags(key, len, hash, flags); + if (shared) { + HeKEY_hek(ent) = share_hek_hek(HeKEY_hek(oent)); + } + else { + const U32 hash = HeHASH(oent); + const char * const key = HeKEY(oent); + const STRLEN len = HeKLEN(oent); + const int flags = HeKFLAGS(oent); + HeKEY_hek(ent) = save_hek_flags(key, len, hash, flags); + } if (prev) HeNEXT(prev) = ent; else |