The code in newCONDOP can be made visibly simpler by using intermediate
authorNicholas Clark <nick@ccl4.org>
Sat, 17 Mar 2007 13:01:18 +0000 (13:01 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 17 Mar 2007 13:01:18 +0000 (13:01 +0000)
variables. It's also 8 bytes smaller with -Os

p4raw-id: //depot/perl@30606

op.c

diff --git a/op.c b/op.c
index 981b765..e6aadae 100644 (file)
--- a/op.c
+++ b/op.c
@@ -4236,38 +4236,24 @@ Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop)
 
     scalarboolean(first);
     if (first->op_type == OP_CONST) {
+       /* Left or right arm of the conditional?  */
+       const bool left = SvTRUE(((SVOP*)first)->op_sv);
+       OP *live = left ? trueop : falseop;
+       OP *const dead = left ? falseop : trueop;
         if (first->op_private & OPpCONST_BARE &&
            first->op_private & OPpCONST_STRICT) {
            no_bareword_allowed(first);
        }
-       if (SvTRUE(((SVOP*)first)->op_sv)) {
-#ifdef PERL_MAD
-           if (PL_madskills) {
-               trueop = newUNOP(OP_NULL, 0, trueop);
-               op_getmad(first,trueop,'C');
-               op_getmad(falseop,trueop,'e');
-           } else
-#endif
-           {
-               op_free(first);
-               op_free(falseop);
-           }
-           return trueop;
-       }
-       else {
-#ifdef PERL_MAD
-           if (PL_madskills) {
-               falseop = newUNOP(OP_NULL, 0, falseop);
-               op_getmad(first,falseop,'C');
-               op_getmad(trueop,falseop,'t');
-           } else
-#endif
-           {
-               op_free(first);
-               op_free(trueop);
-           }
-           return falseop;
+       if (PL_madskills) {
+           /* This is all dead code when PERL_MAD is not defined.  */
+           live = newUNOP(OP_NULL, 0, live);
+           op_getmad(first, live, 'C');
+           op_getmad(dead, live, left ? 'e' : 't');
+       } else {
+           op_free(first);
+           op_free(dead);
        }
+       return live;
     }
     NewOp(1101, logop, 1, LOGOP);
     logop->op_type = OP_COND_EXPR;