Skip to content

Commit

Permalink
pp_aassign: optimise SV branch under PERL_RC_STACK
Browse files Browse the repository at this point in the history
The block of code that handles

    ($scalar, ...) = (...);

used to handle things specially if $scalar was currently a ref, in case
assigning to $scalar freed the referent which was later used on the RHS.
With a ref-counted stack that is no longer a problem.

All changes are wrapped in '#ifdef PERL_RC_STACK' etc.
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent 5e1f7ad commit d899222
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pp_hot.c
Expand Up @@ -3130,8 +3130,6 @@ PP(pp_aassign)

default:
if (!SvIMMORTAL(lsv)) {
SV *ref;

if (UNLIKELY(
rpp_is_lone(lsv) && !SvSMAGICAL(lsv) &&
(!isGV_with_GP(lsv) || SvFAKE(lsv)) && ckWARN(WARN_MISC)
Expand All @@ -3141,8 +3139,10 @@ PP(pp_aassign)
"Useless assignment to a temporary"
);

#ifndef PERL_RC_STACK
/* avoid freeing $$lsv if it might be needed for further
* elements, e.g. ($ref, $foo) = (1, $$ref) */
SV *ref;
if ( SvROK(lsv)
&& ( ((ref = SvRV(lsv)), SvREFCNT(ref)) == 1)
&& lelem <= lastlelem
Expand All @@ -3157,6 +3157,7 @@ PP(pp_aassign)
(void)tmps_grow_p(ix + (lastlelem - lelem));
PL_tmps_stack[ix] = ref;
}
#endif

sv_setsv(lsv, *relem);
rpp_replace_at(relem, lsv);
Expand Down

0 comments on commit d899222

Please sign in to comment.