This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move pp_leavesublv from pp_hot.c to pp_ctl.c
[perl5.git] / pp_hot.c
index 8d02826..9a869f6 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -671,7 +671,7 @@ PP(pp_add)
 PP(pp_aelemfast)
 {
     dVAR; dSP;
-    AV * const av = PL_op->op_flags & OPf_SPECIAL
+    AV * const av = PL_op->op_type == OP_AELEMFAST_LEX
        ? MUTABLE_AV(PAD_SV(PL_op->op_targ)) : GvAVn(cGVOP_gv);
     const U32 lval = PL_op->op_flags & OPf_MOD;
     SV** const svp = av_fetch(av, PL_op->op_private, lval);
@@ -1404,22 +1404,18 @@ PP(pp_match)
             && !SvROK(TARG))   /* Cannot trust since INTUIT cannot guess ^ */
            goto yup;
     }
-    if (CALLREGEXEC(rx, (char*)s, (char *)strend, (char*)truebase,
-                    minmatch, TARG, NUM2PTR(void*, gpos), r_flags))
-    {
-       PL_curpm = pm;
-       if (dynpm->op_pmflags & PMf_ONCE) {
+    if (!CALLREGEXEC(rx, (char*)s, (char *)strend, (char*)truebase,
+                    minmatch, TARG, NUM2PTR(void*, gpos), r_flags))
+       goto ret_no;
+
+    PL_curpm = pm;
+    if (dynpm->op_pmflags & PMf_ONCE) {
 #ifdef USE_ITHREADS
-            SvREADONLY_on(PL_regex_pad[dynpm->op_pmoffset]);
+       SvREADONLY_on(PL_regex_pad[dynpm->op_pmoffset]);
 #else
-           dynpm->op_pmflags |= PMf_USED;
+       dynpm->op_pmflags |= PMf_USED;
 #endif
-        }
-       goto gotcha;
     }
-    else
-       goto ret_no;
-    /*NOTREACHED*/
 
   gotcha:
     if (rxtainted)
@@ -2441,8 +2437,7 @@ PP(pp_subst)
 #endif
        if (RX_MATCH_TAINTED(rx)) /* run time pattern taint, eg locale */
            rxtainted |= SUBST_TAINT_PAT;
-       dstr = newSVpvn_utf8(m, s-m, DO_UTF8(TARG));
-       SAVEFREESV(dstr);
+       dstr = newSVpvn_flags(m, s-m, SVs_TEMP | (DO_UTF8(TARG) ? SVf_UTF8 : 0));
        PL_curpm = pm;
        if (!c) {
            register PERL_CONTEXT *cx;
@@ -2615,7 +2610,7 @@ PP(pp_leavesub)
        MARK = newsp + 1;
        if (MARK <= SP) {
            if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
-               if (SvTEMP(TOPs)) {
+               if (SvTEMP(TOPs) && SvREFCNT(TOPs) == 1) {
                    *MARK = SvREFCNT_inc(TOPs);
                    FREETMPS;
                    sv_2mortal(*MARK);
@@ -2628,7 +2623,7 @@ PP(pp_leavesub)
                    SvREFCNT_dec(sv);
                }
            }
-           else if (SvTEMP(TOPs)) {
+           else if (SvTEMP(TOPs) && SvREFCNT(TOPs) == 1) {
                *MARK = TOPs;
                if (gmagic) SvGETMAGIC(TOPs);
            }
@@ -2643,7 +2638,7 @@ PP(pp_leavesub)
     }
     else if (gimme == G_ARRAY) {
        for (MARK = newsp + 1; MARK <= SP; MARK++) {
-           if (!SvTEMP(*MARK)) {
+           if (!SvTEMP(*MARK) || SvREFCNT(*MARK) != 1) {
                *MARK = sv_mortalcopy(*MARK);
                TAINT_NOT;      /* Each item is independent */
            }
@@ -2660,195 +2655,6 @@ PP(pp_leavesub)
     return cx->blk_sub.retop;
 }
 
-/* This duplicates the above code because the above code must not
- * get any slower by more conditions */
-PP(pp_leavesublv)
-{
-    dVAR; dSP;
-    SV **mark;
-    SV **newsp;
-    PMOP *newpm;
-    I32 gimme;
-    register PERL_CONTEXT *cx;
-    SV *sv;
-
-    if (CxMULTICALL(&cxstack[cxstack_ix]))
-       return 0;
-
-    POPBLOCK(cx,newpm);
-    cxstack_ix++; /* temporarily protect top context */
-
-    TAINT_NOT;
-
-    if (CxLVAL(cx) & OPpENTERSUB_INARGS) {
-       /* We are an argument to a function or grep().
-        * This kind of lvalueness was legal before lvalue
-        * subroutines too, so be backward compatible:
-        * cannot report errors.  */
-
-       /* Scalar context *is* possible, on the LHS of ->. */
-       if (gimme == G_SCALAR)
-           goto rvalue;
-       if (gimme == G_ARRAY) {
-           mark = newsp + 1;
-           if (!CvLVALUE(cx->blk_sub.cv))
-               goto rvalue_array;
-           EXTEND_MORTAL(SP - newsp);
-           for (mark = newsp + 1; mark <= SP; mark++) {
-               if (SvTEMP(*mark))
-                   NOOP;
-               else if (SvFLAGS(*mark) & SVs_PADTMP
-                     || (SvFLAGS(*mark) & (SVf_READONLY|SVf_FAKE))
-                          == SVf_READONLY)
-                   *mark = sv_mortalcopy(*mark);
-               else {
-                   /* Can be a localized value subject to deletion. */
-                   PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc_void(*mark);
-               }
-           }
-       }
-    }
-    else if (CxLVAL(cx)) {     /* Leave it as it is if we can. */
-       /* Here we go for robustness, not for speed, so we change all
-        * the refcounts so the caller gets a live guy. Cannot set
-        * TEMP, so sv_2mortal is out of question. */
-       if (!CvLVALUE(cx->blk_sub.cv)) {
-           LEAVE;
-           cxstack_ix--;
-           POPSUB(cx,sv);
-           PL_curpm = newpm;
-           LEAVESUB(sv);
-           DIE(aTHX_ "Can't modify non-lvalue subroutine call");
-       }
-       if (gimme == G_SCALAR) {
-           MARK = newsp + 1;
-           EXTEND_MORTAL(1);
-           if (MARK == SP) {
-               if ((SvPADTMP(TOPs) ||
-                    (SvFLAGS(TOPs) & (SVf_READONLY | SVf_FAKE))
-                      == SVf_READONLY
-                   ) &&
-                   !SvSMAGICAL(TOPs)) {
-                   LEAVE;
-                   cxstack_ix--;
-                   POPSUB(cx,sv);
-                   PL_curpm = newpm;
-                   LEAVESUB(sv);
-                   DIE(aTHX_ "Can't return %s from lvalue subroutine",
-                       SvREADONLY(TOPs) ? (TOPs == &PL_sv_undef) ? "undef"
-                       : "a readonly value" : "a temporary");
-               }
-               else {                  /* Can be a localized value
-                                        * subject to deletion. */
-                   PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc_void(*mark);
-               }
-           }
-           else {
-               /* sub:lvalue{} will take us here.
-                  Presumably the case of a non-empty array never happens.
-                */
-               LEAVE;
-               cxstack_ix--;
-               POPSUB(cx,sv);
-               PL_curpm = newpm;
-               LEAVESUB(sv);
-               DIE(aTHX_ "%s",
-                   (MARK > SP
-                     ? "Can't return undef from lvalue subroutine"
-                     : "Array returned from lvalue subroutine in scalar "
-                       "context"
-                   )
-               );
-           }
-           SP = MARK;
-       }
-       else if (gimme == G_ARRAY) {
-           EXTEND_MORTAL(SP - newsp);
-           for (mark = newsp + 1; mark <= SP; mark++) {
-               if (*mark != &PL_sv_undef
-                   && (SvPADTMP(*mark)
-                      || (SvFLAGS(*mark) & (SVf_READONLY|SVf_FAKE))
-                            == SVf_READONLY
-                      )
-               ) {
-                   /* Might be flattened array after $#array =  */
-                   PUTBACK;
-                   LEAVE;
-                   cxstack_ix--;
-                   POPSUB(cx,sv);
-                   PL_curpm = newpm;
-                   LEAVESUB(sv);
-                   DIE(aTHX_ "Can't return a %s from lvalue subroutine",
-                       SvREADONLY(TOPs) ? "readonly value" : "temporary");
-               }
-               else {
-                   /* Can be a localized value subject to deletion. */
-                   PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc_void(*mark);
-               }
-           }
-       }
-    }
-    else {
-       if (gimme == G_SCALAR) {
-         rvalue:
-           MARK = newsp + 1;
-           if (MARK <= SP) {
-               if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
-                       *MARK = SvREFCNT_inc(TOPs);
-                       FREETMPS;
-                       sv_2mortal(*MARK);
-               }
-               else
-                   *MARK = SvTEMP(TOPs)
-                             ? TOPs
-                             : sv_2mortal(SvREFCNT_inc_simple_NN(TOPs));
-           }
-           else {
-               MEXTEND(MARK, 0);
-               *MARK = &PL_sv_undef;
-           }
-           SP = MARK;
-       }
-       else if (gimme == G_ARRAY) {
-         rvalue_array:
-           for (MARK = newsp + 1; MARK <= SP; MARK++) {
-               if (!SvTEMP(*MARK))
-                   *MARK = sv_2mortal(SvREFCNT_inc_simple_NN(*MARK));
-           }
-       }
-    }
-
-    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;
-    cxstack_ix--;
-    POPSUB(cx,sv);     /* Stack values are safe: release CV and @_ ... */
-    PL_curpm = newpm;  /* ... and pop $1 et al */
-
-    LEAVESUB(sv);
-    return cx->blk_sub.retop;
-}
-
 PP(pp_entersub)
 {
     dVAR; dSP; dPOPss;