This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
rpeep(): skip duplicate nextstates even with gaps
authorDavid Mitchell <davem@iabyn.com>
Sat, 21 Sep 2019 11:24:45 +0000 (12:24 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 23 Sep 2019 13:42:00 +0000 (14:42 +0100)
rpeep() already optimises away consecutive nextstate ops. This commit
makes it do this even if there are 'noop' ops between them like null,
scope, lineseq.

This has a specific utility for the next commit, which will reorganise
the optree for subroutine signatures in a way which introduces a lineseq
between two nextstates.

op.c

diff --git a/op.c b/op.c
index 29486a5..89d75dc 100644 (file)
--- a/op.c
+++ b/op.c
@@ -16087,8 +16087,17 @@ Perl_rpeep(pTHX_ OP *o)
               this optimisation if the first NEXTSTATE has a label.  */
            if (!CopLABEL((COP*)o) && !PERLDB_NOOPT) {
                OP *nextop = o->op_next;
               this optimisation if the first NEXTSTATE has a label.  */
            if (!CopLABEL((COP*)o) && !PERLDB_NOOPT) {
                OP *nextop = o->op_next;
-               while (nextop && nextop->op_type == OP_NULL)
-                   nextop = nextop->op_next;
+               while (nextop) {
+                    switch (nextop->op_type) {
+                        case OP_NULL:
+                        case OP_SCALAR:
+                        case OP_LINESEQ:
+                        case OP_SCOPE:
+                            nextop = nextop->op_next;
+                            continue;
+                    }
+                    break;
+                }
 
                if (nextop && (nextop->op_type == OP_NEXTSTATE)) {
                    op_null(o);
 
                if (nextop && (nextop->op_type == OP_NEXTSTATE)) {
                    op_null(o);