Show performance warnings for easily avoidable unnecessary implicit splat allocations #13135
+120
−10
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.
For the following method calls:
If
kw
andblock
are method calls, Ruby must allocate an array for*ary
and a hash for**hash
, to avoid an evaluation order issue in the case wherekw
orblock
methods modifyary
orhash
.These implicit allocations are trivial to avoid by assigning the values to a local variable:
Ruby does not to allocate an array for
*ary
or a hash for**kw
in these cases, because there is no evaluation order issue.To help users optimize their code to avoid these unnecessary implicit allocations, this adds performance warnings in these cases, letting users know that they can optimize their code by assinging to a local variable: