From e95ec34bc73b3b11ef1a5fdc98fd887ae6583a02 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Thu, 31 Jul 2025 23:17:26 +0000 Subject: [PATCH 1/2] peep.c: remove childless OP_NULL nodes in a list --- peep.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/peep.c b/peep.c index 5980ea1c2fca..28bba3940845 100644 --- a/peep.c +++ b/peep.c @@ -3124,6 +3124,23 @@ 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 5 repeat/DOLIST 3 ex-list From 3a09ea483bddac42287f79287b465dc726af0e83 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Thu, 31 Jul 2025 23:33:11 +0000 Subject: [PATCH 2/2] peep.c: optimise OP_LIST in scalar context Note: This shouldn't occur particularly frequently, as superfluous arguments are likely to trigger warnings when scalar context is applied to the list. e.g. `my $x = (1,2,3);` is essentially the same as `my $x = 3;` --- peep.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/peep.c b/peep.c index 28bba3940845..6bbe66f905cc 100644 --- a/peep.c +++ b/peep.c @@ -3141,6 +3141,26 @@ Perl_rpeep(pTHX_ OP *o) } } + /* 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