This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SAVEt_CLEARSV: simplify SvREADONLY_off() condition
authorDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 17:51:47 +0000 (17:51 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 28 Feb 2014 19:38:37 +0000 (19:38 +0000)
SAVEt_CLEARSV should always be called with SvPADMY() true, so don't test
for it, but assert it instead. Then change this:

    if (SvPADMY(sv) && !SvFAKE(sv))
         SvREADONLY_off(sv);

The SvPADMY() isn't needed, but we should test for RO-ness instead, to
avoid an unnecessary SvREADONLY_off().

scope.c

diff --git a/scope.c b/scope.c
index 4361455..23ade78 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1036,6 +1036,8 @@ Perl_leave_scope(pTHX_ I32 base)
                     (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon"
                 ));
 
+                assert(SvPADMY(sv));
+
                 /* Can clear pad variable in place? */
                 if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
 
@@ -1056,7 +1058,7 @@ Perl_leave_scope(pTHX_ I32 base)
                          * readonlyness so that it can go out of scope
                          * quietly
                          */
-                        if (SvPADMY(sv) && !SvFAKE(sv))
+                        if (SvREADONLY(sv) && !SvFAKE(sv))
                             SvREADONLY_off(sv);
 
                         if (SvMAGICAL(sv)) {