Skip to content

Commit

Permalink
pp_aassign: optimise: just zero array stack elems
Browse files Browse the repository at this point in the history
In PERL_RC_STACK builds, When passing ownership of a bunch of SVs on the
stack to an array 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 a9c67a3 commit e5a34b5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pp_hot.c
Expand Up @@ -2871,12 +2871,14 @@ PP(pp_aassign)
/* ownership of one ref count of each elem passed to
* array. Quietly remove old SVs from stack, or if need
* to keep the list on the stack too, bump the count */
if (is_list)
if (UNLIKELY(is_list))
for (i = 0; i < nelems; i++)
SvREFCNT_inc_void_NN(relem[i]);
else
for (i = 0; i < nelems; i++)
relem[i] = &PL_sv_undef;
else {
assert(first_discard == relem + nelems);
Zero(relem, nelems, SV*);
first_discard = relem;
}
#else
Copy(&(PL_tmps_stack[tmps_base]), AvARRAY(ary), nelems, SV*);
/* Quietly remove all the SVs from the tmps stack slots,
Expand Down

0 comments on commit e5a34b5

Please sign in to comment.