Skip to content

Commit

Permalink
pp_aassign: optimise: just zero hash stack elems
Browse files Browse the repository at this point in the history
Similar to the previous commit but for hashes rather than arrays,
in PERL_RC_STACK builds, When passing ownership of a bunch of SVs on the
stack to a hash they've just been stored in, just zero out that
section of the stack and shift first_discard downwards, rather than
storing &PL_sv_undef in all the stack slots. This means that at the end,
PL_stack_sp can be reset directly to the base of those elements rather
than decrementing the ref count of &PL_sv_undef N times.
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent e5a34b5 commit c4e9fef
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pp_hot.c
Expand Up @@ -3138,17 +3138,33 @@ PP(pp_aassign)
for (i = 0, svp = relem; svp <= lastrelem; i++, svp++) {
SV *key = *svp++;
SV *val = *svp;
if (hv_store_ent(hash, key, val, 0))
#ifdef PERL_RC_STACK
SvREFCNT_inc_simple_NN(val);
{
HE *stored = hv_store_ent(hash, key, val, 0);
/* hv_store_ent() may have added set magic to val */;
SvSETMAGIC(val);
/* remove key and val from stack */
*svp = NULL;
if (!stored)
SvREFCNT_dec_NN(val);
svp[-1] = NULL;
SvREFCNT_dec_NN(key);
}
#else
if (hv_store_ent(hash, key, val, 0))
PL_tmps_stack[tmps_base + i] = &PL_sv_undef;
else
dirty_tmps = TRUE;
#endif
/* hv_store_ent() may have added set magic to val */;
SvSETMAGIC(val);
#endif
}
#ifdef PERL_RC_STACK
/* now that all the key and val slots on the stack have
* been discarded, we can skip freeing them on return */
assert(first_discard == lastrelem + 1);
first_discard = relem;
#endif
}

#ifdef PERL_RC_STACK
Expand Down

0 comments on commit c4e9fef

Please sign in to comment.