Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use for_each to extend collections #59740

Merged
merged 1 commit into from
Apr 7, 2019
Merged

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Apr 5, 2019

This updates the Extend implementations to use for_each for many
collections: BinaryHeap, BTreeMap, BTreeSet, LinkedList, Path,
TokenStream, VecDeque, and Wtf8Buf.

Folding with for_each enables better performance than a for-loop for
some iterators, especially if they can just forward to internal
iterators, like Chain and FlatMap do.

This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
@rust-highfive
Copy link
Collaborator

r? @TimNN

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 5, 2019
@cuviper
Copy link
Member Author

cuviper commented Apr 5, 2019

For reference:

@Centril
Copy link
Contributor

Centril commented Apr 5, 2019

r? @scottmcm

@rust-highfive rust-highfive assigned scottmcm and unassigned TimNN Apr 5, 2019
@Mark-Simulacrum
Copy link
Member

To get at least a sense that this isn't obviously bad (though I don't expect it to be), let's @bors try

@bors
Copy link
Contributor

bors commented Apr 6, 2019

⌛ Trying commit 0730a01 with merge eab4756...

bors added a commit that referenced this pull request Apr 6, 2019
Use for_each to extend collections

This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
@scottmcm
Copy link
Member

scottmcm commented Apr 6, 2019

r=me when perf is happy

@scottmcm
Copy link
Member

scottmcm commented Apr 6, 2019

Actually, you might check for while let loops too:

while let Some(element) = iterator.next() {

@cuviper
Copy link
Member Author

cuviper commented Apr 6, 2019

I see, the previous Vec improvement was only for I: TrustedLen. I'll look for more...

@cuviper
Copy link
Member Author

cuviper commented Apr 6, 2019

@scottmcm that one is difficult, because it wants to check size_hint() every time it needs to grow, which we can't do while folding...

@bors
Copy link
Contributor

bors commented Apr 6, 2019

☀️ Try build successful - checks-travis
Build commit: eab4756

@cuviper
Copy link
Member Author

cuviper commented Apr 6, 2019

@rust-timer build eab4756

@rust-timer
Copy link
Collaborator

Success: Queued eab4756 with parent acd8dd6, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit eab4756

@scottmcm
Copy link
Member

scottmcm commented Apr 6, 2019

@cuviper Oops! You're right. And perf looks happy, so

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 6, 2019

📌 Commit 0730a01 has been approved by scottmcm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2019
@bors

This comment has been minimized.

@bors

This comment has been minimized.

Centril added a commit to Centril/rust that referenced this pull request Apr 6, 2019
Use for_each to extend collections

This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
Centril added a commit to Centril/rust that referenced this pull request Apr 6, 2019
Use for_each to extend collections

This updates the `Extend` implementations to use `for_each` for many
collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`,
`TokenStream`, `VecDeque`, and `Wtf8Buf`.

Folding with `for_each` enables better performance than a `for`-loop for
some iterators, especially if they can just forward to internal
iterators, like `Chain` and `FlatMap` do.
bors added a commit that referenced this pull request Apr 6, 2019
Rollup of 5 pull requests

Successful merges:

 - #59738 (Move match_path from DefId to lint::LateContext)
 - #59740 (Use for_each to extend collections)
 - #59751 (Tiny docs fix)
 - #59754 (Update books)
 - #59755 (Update miri)

Failed merges:

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants