Skip to content

Commit

Permalink
Perl_newHVhv should use share_hek_hek() instead of share_hek_flags()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nwc10 committed Oct 20, 2021
1 parent 33042aa commit a31d036
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a31d036

Please sign in to comment.