Skip to content

Commit

Permalink
use rpp_replace_at_norc in refassign, aassign
Browse files Browse the repository at this point in the history
Use the just-added function rpp_replace_at_norc() to simplify some blocks
of code recently added to pp_refassign() and pp_aassign()
  • Loading branch information
iabyn committed Nov 16, 2023
1 parent 2bb1814 commit 4a7d95d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
8 changes: 1 addition & 7 deletions pp.c
Expand Up @@ -7400,13 +7400,7 @@ PP(pp_refassign)
if (UNLIKELY(PL_op->op_flags & OPf_MOD)) {
/* e.g. f(\$x = \1); */
rpp_popfree_to(PL_stack_sp - extra);
SV *nsv = newSVsv(sv);
#ifdef PERL_RC_STACK
rpp_replace_1_1(nsv);
SvREFCNT_dec_NN(nsv);
#else
rpp_replace_1_1(sv_2mortal(nsv));
#endif
rpp_replace_at_norc(PL_stack_sp, newSVsv(sv));
/* XXX else can weak references go stale before they are read, e.g.,
in leavesub? */
}
Expand Down
42 changes: 21 additions & 21 deletions pp_hot.c
Expand Up @@ -2786,9 +2786,13 @@ PP(pp_aassign)
* SV_NOSTEAL */
nsv = newSVsv_flags(rsv,
(SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC));
rpp_replace_at(svp, nsv);
#ifdef PERL_RC_STACK
SvREFCNT_dec_NN(nsv);
rpp_replace_at_norc(svp, nsv);
#else
/* using rpp_replace_at_norc() would mortalise,
* but we're manually adding nsv to the tmps stack
* below already */
rpp_replace_at(svp, nsv);
#endif

rsv = nsv;
Expand Down Expand Up @@ -2952,9 +2956,13 @@ PP(pp_aassign)
* SV_NOSTEAL */
nsv = newSVsv_flags(rsv,
(SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC));
rpp_replace_at(svp, nsv);
#ifdef PERL_RC_STACK
SvREFCNT_dec_NN(nsv);
rpp_replace_at_norc(svp, nsv);
#else
/* using rpp_replace_at_norc() would mortalise,
* but we're manually adding nsv to the tmps stack
* below already */
rpp_replace_at(svp, nsv);
#endif
rsv = nsv;
}
Expand All @@ -2977,20 +2985,14 @@ PP(pp_aassign)
* @a = ((%h = ($$r, 1)), $r = "x");
* $_++ for %h = (1,2,3,4);
*/
#ifdef PERL_RC_STACK
#ifndef PERL_RC_STACK
EXTEND_MORTAL(nelems);
#endif
for (svp = relem; svp <= lastrelem; svp += 2) {
rpp_replace_at(svp,
rpp_replace_at_norc(svp,
newSVsv_flags(*svp,
SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL));
SvREFCNT_dec_NN(*svp);
}
#else
EXTEND_MORTAL(nelems);
for (svp = relem; svp <= lastrelem; svp += 2)
rpp_replace_at(svp,
sv_mortalcopy_flags(*svp,
SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL));
#endif
}
else if (PL_op->op_private & OPpASSIGN_COMMON_AGG) {
/* for possible commonality, e.g.
Expand All @@ -3011,23 +3013,21 @@ PP(pp_aassign)
#ifdef PERL_RC_STACK
for (svp = relem; svp <= lastrelem; svp += 2) {
SV *rsv = *svp;
if (UNLIKELY(SvGMAGICAL(rsv))) {
if (UNLIKELY(SvGMAGICAL(rsv)))
/* XXX does this actually need to be copied, or
* could we just call the get magic??? */
rpp_replace_at(svp,
newSVsv_flags(*svp,
rpp_replace_at_norc(svp,
newSVsv_flags(rsv,
SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL));
SvREFCNT_dec_NN(*svp);
}
}
#else
EXTEND_MORTAL(nelems);
for (svp = relem; svp <= lastrelem; svp += 2) {
SV *rsv = *svp;
if (UNLIKELY(SvGMAGICAL(rsv))) {
SSize_t n;
rpp_replace_at(svp,
sv_mortalcopy_flags(*svp,
rpp_replace_at_norc(svp,
newSVsv_flags(rsv,
SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL));
/* allow other branch to continue pushing
* onto tmps stack without checking each time */
Expand Down

0 comments on commit 4a7d95d

Please sign in to comment.