Peephole optimizations for NULLs in lists and scalar lists #23523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
my $x = (1,2,3);produces the following OP tree in blead:This is functionally equivalent to
my $x = 3;:Refactoring
Perl_scalar/Perl_scalarvoidto allow the transformation of the first tree into the second is proabably not worth the churn, given that constructing the first tree will typically emit "Useless use of X in scalar context" warnings. Some cases may silently slip through though, such as when the consts0and1are excluded from these warnings.The attached commits enable the peephole optimizer to do two things:
OP_NULLlist nodes, when they have no kids and have a sibling.op_nextpointers to skip over the unnecessaryOP_PUSHMARKandOP_LISTnodes.That gives an OP tree like this:
Closes: #23448