This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_leavesub: simplify recursion test
authorDavid Mitchell <davem@iabyn.com>
Sat, 11 Jul 2015 10:49:13 +0000 (11:49 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:35 +0000 (08:59 +0000)
Part of pp_leavesub() tests whether we're in recursion by looking
at CvDEPTH(cx->blk_sub.cv). Instead, just directly check
cx->blk_sub.olddepth, which is equivalent (allowing for an offset of 1)
but faster.

pp_hot.c

index f719b40..dba67bb 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3282,7 +3282,14 @@ PP(pp_leavesub)
     if (gimme == G_SCALAR) {
        MARK = newsp + 1;
        if (LIKELY(MARK <= SP)) {
-           if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
+            /* if we are recursing, then free the current tmps.
+             * Normally we don't bother and rely on the caller to do this,
+             * because early tmp freeing tends to free the args we're
+             * returning.
+             * Doing it for recursion ensures the things like the
+             * fibonacci benchmark don't fill up the tmps stack because
+             * it never reaches an outer nextstate */
+           if (cx->blk_sub.olddepth) {
                if (SvTEMP(TOPs) && SvREFCNT(TOPs) == 1
                     && !SvMAGICAL(TOPs)) {
                    *MARK = SvREFCNT_inc(TOPs);