Open vlad-pisanov opened 8 months ago
Yeah, this is likely similar to the Performance/ChainArrayAllocation
cop, so I will transfer it to rubocop-performance.
This could substantially reduce allocations/copies, but it's quite a can of worms.
The transformation is equivalent only if list
isn't shared. This is hard enough in a statically-typed language with good lifetime analysis, but even harder in a dynamic language like Ruby.
When the result of
select
,reject
,uniq
,sort
,sort_by
,map
,flatten
, andreverse
is assigned back to the variable it operates on, prefer the mutable version of the method, i.e.This could also be a performance cop since mutating in-place can have performance advantages.