Skip to content

Specialize Vec::from_iter for vec::IntoIter #40731

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 29, 2017

Conversation

sfackler
Copy link
Member

It's fairly common to expose an API which takes an IntoIterator and
immediately collects that into a vector. It's also common to buffer
a bunch of items into a vector and then pass that into one of these
APIs. If the iterator hasn't been advanced, we can make this from_iter
simply reassemble the original Vec with no actual iteration or
reallocation.

r? @aturon

It's fairly common to expose an API which takes an `IntoIterator` and
immediately collects that into a vector. It's also common to buffer
a bunch of items into a vector and then pass that into one of these
APIs. If the iterator hasn't been advanced, we can make this `from_iter`
simply reassemble the original `Vec` with no actual iteration or
reallocation.
@sfackler sfackler force-pushed the vec-from-iter-spec branch from 338aabb to dae66e0 Compare March 22, 2017 08:55
@aturon
Copy link
Member

aturon commented Mar 27, 2017

Very nice!

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 27, 2017

📌 Commit dae66e0 has been approved by aturon

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 29, 2017
Specialize Vec::from_iter for vec::IntoIter

It's fairly common to expose an API which takes an `IntoIterator` and
immediately collects that into a vector. It's also common to buffer
a bunch of items into a vector and then pass that into one of these
APIs. If the iterator hasn't been advanced, we can make this `from_iter`
simply reassemble the original `Vec` with no actual iteration or
reallocation.

r? @aturon
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 29, 2017
Specialize Vec::from_iter for vec::IntoIter

It's fairly common to expose an API which takes an `IntoIterator` and
immediately collects that into a vector. It's also common to buffer
a bunch of items into a vector and then pass that into one of these
APIs. If the iterator hasn't been advanced, we can make this `from_iter`
simply reassemble the original `Vec` with no actual iteration or
reallocation.

r? @aturon
bors added a commit that referenced this pull request Mar 29, 2017
Rollup of 5 pull requests

- Successful merges: #40682, #40731, #40783, #40838, #40864
- Failed merges:
@bors bors merged commit dae66e0 into rust-lang:master Mar 29, 2017
@sfackler sfackler deleted the vec-from-iter-spec branch November 29, 2017 23:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants