This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_leavesublv: Put the deref code inside if(scalar)
authorFather Chrysostomos <sprout@cpan.org>
Thu, 23 Jun 2011 02:03:32 +0000 (19:03 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 23 Jun 2011 13:04:02 +0000 (06:04 -0700)
No need to check it in list context (but still assert that).

pp_ctl.c

index af520af..95f2856 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2500,8 +2500,24 @@ PP(pp_leavesublv)
            }
            SP = MARK;
        }
+       if (CxLVAL(cx) & OPpENTERSUB_DEREF) {
+         SvGETMAGIC(TOPs);
+         if (!SvOK(TOPs)) {
+           U8 deref_type;
+           if (cx->blk_sub.retop->op_type == OP_RV2SV)
+               deref_type = OPpDEREF_SV;
+           else if (cx->blk_sub.retop->op_type == OP_RV2AV)
+               deref_type = OPpDEREF_AV;
+           else {
+               assert(cx->blk_sub.retop->op_type == OP_RV2HV);
+               deref_type = OPpDEREF_HV;
+           }
+           vivify_ref(TOPs, deref_type);
+         }
+       }
     }
     else if (gimme == G_ARRAY) {
+       assert(!(CxLVAL(cx) & OPpENTERSUB_DEREF));
        if (CxLVAL(cx) & OPpENTERSUB_INARGS) {
        /* We are an argument to a function or grep().
         * This kind of lvalueness was legal before lvalue
@@ -2555,23 +2571,6 @@ PP(pp_leavesublv)
        }
     }
 
-    if (CxLVAL(cx) & OPpENTERSUB_DEREF) {
-       assert(gimme == G_SCALAR);
-       SvGETMAGIC(TOPs);
-       if (!SvOK(TOPs)) {
-           U8 deref_type;
-           if (cx->blk_sub.retop->op_type == OP_RV2SV)
-               deref_type = OPpDEREF_SV;
-           else if (cx->blk_sub.retop->op_type == OP_RV2AV)
-               deref_type = OPpDEREF_AV;
-           else {
-               assert(cx->blk_sub.retop->op_type == OP_RV2HV);
-               deref_type = OPpDEREF_HV;
-           }
-           vivify_ref(TOPs, deref_type);
-       }
-    }
-
     PUTBACK;
 
     LEAVE;