Skip to content

Commit

Permalink
pp_aassign: fix "RC==1" optimisation checks
Browse files Browse the repository at this point in the history
The code sometimes skips a copying step if the ref count of the SV
is 1. Under PERL_RC_STACK, the ref count can now be 2, with the
optimisation still being valid.
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent 33d9495 commit c0878a0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pp_hot.c
Expand Up @@ -2461,7 +2461,14 @@ S_aassign_copy_common(pTHX_ SV **firstlelem, SV **lastlelem,
lcount = -1;
lelem--; /* no need to unmark this element */
}
else if (!(do_rc1 && SvREFCNT(svl) == 1) && !SvIMMORTAL(svl)) {
else if (!(do_rc1 &&
#ifdef PERL_RC_STACK
SvREFCNT(svl) <= 2
#else
SvREFCNT(svl) == 1
#endif
) && !SvIMMORTAL(svl))
{
SvFLAGS(svl) |= SVf_BREAK;
marked = TRUE;
}
Expand Down Expand Up @@ -2589,7 +2596,13 @@ PP(pp_aassign)
/* skip the scan if all scalars have a ref count of 1 */
for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
SV *sv = *lelem;
if (!sv || SvREFCNT(sv) == 1)
if (!sv ||
#ifdef PERL_RC_STACK
SvREFCNT(sv) <= 2
#else
SvREFCNT(sv) == 1
#endif
)
continue;
if (SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVAV)
goto do_scan;
Expand Down

0 comments on commit c0878a0

Please sign in to comment.