This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: S_search_const: remove recursion
authorDavid Mitchell <davem@iabyn.com>
Tue, 28 May 2019 16:37:43 +0000 (17:37 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 24 Jun 2019 10:40:07 +0000 (11:40 +0100)
There are a couple of places where this function recurses, but they
are both effectively tail recursion and can be easily eliminated.

op.c

diff --git a/op.c b/op.c
index ab185fd..f76087a 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8365,12 +8365,15 @@ S_search_const(pTHX_ OP *o)
 {
     PERL_ARGS_ASSERT_SEARCH_CONST;
 
+  redo:
     switch (o->op_type) {
        case OP_CONST:
            return o;
        case OP_NULL:
-           if (o->op_flags & OPf_KIDS)
-               return search_const(cUNOPo->op_first);
+           if (o->op_flags & OPf_KIDS) {
+               o = cUNOPo->op_first;
+                goto redo;
+            }
            break;
        case OP_LEAVE:
        case OP_SCOPE:
@@ -8398,7 +8401,8 @@ S_search_const(pTHX_ OP *o)
            if (!kid)
                kid = cLISTOPo->op_last;
           last:
-           return search_const(kid);
+            o = kid;
+             goto redo;
        }
     }