This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
push in Void Context
authorchromatic <chromatic@wgz.org>
Tue, 22 Sep 2009 15:33:33 +0000 (08:33 -0700)
committerJesse Vincent <jesse@bestpractical.com>
Tue, 22 Sep 2009 21:24:05 +0000 (06:24 +0900)
The attached patch avoids pushing an IV onto the stack for a push op
in void context.  The "Is there attached magic" branch in the op checks
for void context as does the non-magical branch in the unshift op.

-- c

[Edited version of patch after review by Yitzchak Scott-Thoennes]

pp.c

diff --git a/pp.c b/pp.c
index e3b7798..fae2d6d 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4738,7 +4738,9 @@ PP(pp_push)
 
        PL_delaymagic = 0;
        SP = ORIGMARK;
-       PUSHi( AvFILLp(ary) + 1 );
+       if (OP_GIMME(PL_op, 0) != G_VOID) {
+           PUSHi( AvFILL(ary) + 1 );
+       }
     }
     RETURN;
 }