This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
s/// in boolean context: simplify return value
authorDavid Mitchell <davem@iabyn.com>
Tue, 19 Dec 2017 15:28:06 +0000 (15:28 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 19 Dec 2017 15:28:06 +0000 (15:28 +0000)
Normally s/// returns a count of the number of iterations, but
as an optimisation, in boolean context it returns PL_sv_yes/PL_sv_zero
instead. But in the places where it decides which immortal var to return,
the number of iterations is always > 0, so PL_sv_zero never gets returned.
So skip testing whether iters > 0 and always just return PL_sv_yes.

(In non-boolean scalar context, it still returns the iteration count as
before.)

pp_hot.c

index bba90a8..21b1f16 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -4361,8 +4361,9 @@ PP(pp_subst)
                Move(s, d, i+1, char);          /* include the NUL */
            }
            SPAGAIN;
                Move(s, d, i+1, char);          /* include the NUL */
            }
            SPAGAIN;
+            assert(iters);
             if (PL_op->op_private & OPpTRUEBOOL)
             if (PL_op->op_private & OPpTRUEBOOL)
-                PUSHs(iters ? &PL_sv_yes : &PL_sv_zero);
+                PUSHs(&PL_sv_yes);
             else
                 mPUSHi(iters);
        }
             else
                 mPUSHi(iters);
        }
@@ -4471,7 +4472,7 @@ PP(pp_subst)
 
            SPAGAIN;
             if (PL_op->op_private & OPpTRUEBOOL)
 
            SPAGAIN;
             if (PL_op->op_private & OPpTRUEBOOL)
-                PUSHs(iters ? &PL_sv_yes : &PL_sv_zero);
+                PUSHs(&PL_sv_yes);
             else
                 mPUSHi(iters);
        }
             else
                 mPUSHi(iters);
        }