This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SAVEt_CLEARSV: handle SvOOK() specially
authorDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 18:40:10 +0000 (18:40 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 19:38:49 +0000 (19:38 +0000)
Add SVf_OOK to the list of flags that are handled in the 'slow' branch.
This allows us to avoid checking for hv_kill_backrefs() or sv_backoff()
for the majority of lexicals which won't require it.

scope.c

diff --git a/scope.c b/scope.c
index 6bef7b0..d326220 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1041,16 +1041,12 @@ Perl_leave_scope(pTHX_ I32 base)
                 /* Can clear pad variable in place? */
                 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
 
-                    /* note that backrefs (either in HvAUX or magic)
-                     * must be removed before other magic */
-                    if (SvTYPE(sv) == SVt_PVHV)
-                        Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
-
                     /* these flags are the union of all the relevant flags
                      * in the individual conditions within */
                     if (UNLIKELY(SvFLAGS(sv) & (
                             SVf_READONLY /* for SvREADONLY_off() */
                           | (SVs_GMG|SVs_SMG|SVs_RMG) /* SvMAGICAL() */
+                          | SVf_OOK
                           | SVf_THINKFIRST)))
                     {
                         /* if a my variable that was made readonly is
@@ -1061,7 +1057,16 @@ Perl_leave_scope(pTHX_ I32 base)
                         if (SvREADONLY(sv) && !SvFAKE(sv))
                             SvREADONLY_off(sv);
 
+                        if (SvOOK(sv)) { /* OOK or HvAUX */
+                            if (SvTYPE(sv) == SVt_PVHV)
+                                Perl_hv_kill_backrefs(aTHX_ MUTABLE_HV(sv));
+                            else
+                                sv_backoff(sv);
+                        }
+
                         if (SvMAGICAL(sv)) {
+                            /* note that backrefs (either in HvAUX or magic)
+                             * must be removed before other magic */
                             sv_unmagic(sv, PERL_MAGIC_backref);
                             if (SvTYPE(sv) != SVt_PVCV)
                                 mg_free(sv);
@@ -1093,8 +1098,6 @@ Perl_leave_scope(pTHX_ I32 base)
                         assert_not_ROK(sv);
                         assert_not_glob(sv);
                         SvFLAGS(sv) &=~ (SVf_OK|SVf_IVisUV|SVf_UTF8);
-                        if (SvOOK(sv))
-                            sv_backoff(sv);
                         break;
                     }
                     SvPADSTALE_on(sv); /* mark as no longer live */