Skip to content

Peephole optimizations for NULLs in lists and scalar lists #23523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: blead
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions peep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading