diff --git a/peep.c b/peep.c index 5980ea1c2fca..6bbe66f905cc 100644 --- a/peep.c +++ b/peep.c @@ -3124,6 +3124,43 @@ Perl_rpeep(pTHX_ OP *o) case OP_PUSHMARK: + /* Given + pushmark + null + something_else + Take out the null wherever possible. + */ + while (OP_TYPE_IS(o->op_next, OP_NULL)) { + OP* next = o->op_next; + o->op_next = next->op_next; + if (OpSIBLING(o) == next && + next->op_moresib && + !(next->op_flags & OPf_KIDS)) { + op_sibling_splice(NULL, o, 1, NULL); + op_free(next); + } + } + + /* Given + list (in scalar context) + pushmark + something + The pushmark & list OPs are unnecessary. + */ + + { + OP *nn = o->op_next->op_next; + if (OP_TYPE_IS(nn, OP_LIST) && + ((nn->op_flags & OPf_WANT) == OPf_WANT_SCALAR) ) { + if (oldop) + oldop->op_next = o->op_next; + o->op_next->op_next = nn->op_next; + op_null(nn); + op_null(o); + oldop = NULL; oldoldop = NULL; + } + } + /* Given 5 repeat/DOLIST 3 ex-list