-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Add Iterator::collect_into<E: Extend>(e: E)? #45840
Copy link
Copy link
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Hey gang.
As originally determined in https://twitter.com/kot_2010/status/927119253324619776, building a pre-size-hinted mutable
Vecas the output of a loop (even for very smalln) can occasionally be more than twice as fast ascollecting into aVec. As demonstrated here https://github.com/stuhood/rust-vec-bench, usingextendinto a pre-size-hintedVeccloses most of the gap.Focusing on improving
Iterator::size_hintimplementations so that they suggest better sizes forcollectwould likely help reduce this gap. But there are diminishing returns to heuristics, and in many cases users should be able to give better explicit hints.This issue initially proposed adding an
Iterator::collect_with_size_hintmethod, but @scottmcm 's suggestion to addIterator::collect_into<E: Extend>(e: E) -> Eseems more general, and suggests a useful analogue inunzip_into<E1: Extend, E2: Extend>(e1: E1, e2: E2) -> (E1, E2).