You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend::extend takes an IntoIterator. Since every Iterator is also an IntoIterator, you can extend from an iterator; collect() an iterator before extend() from it leads to extra memory allocations and extra copying, and is probably a mistake.
Lint Name
extend_collect
Category
suspicious, perf
Advantage
Fewer memory allocations and fewer copying.
Drawbacks
Maybe collect() actually leads to a performance boost because of, say, better cache behavior, and is actually intentional.
Example
letmut v = vec![0i32];
v.extend((1..10).collect::<Vec<_>>());
Could be written as:
letmut v = vec![0i32];
v.extend(1..10);
The text was updated successfully, but these errors were encountered:
jovenlin0527
changed the title
Use extend(some_iter) over .extend(some_iter.collect())`
Use extend(some_iter) over .extend(some_iter.collect())May 9, 2023
jovenlin0527
changed the title
Use extend(some_iter) over .extend(some_iter.collect())
Use .extend(some_iter) over .extend(some_iter.collect())May 9, 2023
What it does
Extend::extend
takes anIntoIterator
. Since everyIterator
is also anIntoIterator
, you canextend
from an iterator;collect()
an iterator beforeextend()
from it leads to extra memory allocations and extra copying, and is probably a mistake.Lint Name
extend_collect
Category
suspicious, perf
Advantage
Fewer memory allocations and fewer copying.
Drawbacks
Maybe
collect()
actually leads to a performance boost because of, say, better cache behavior, and is actually intentional.Example
Could be written as:
The text was updated successfully, but these errors were encountered: