-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Have all methods of Filter and FilterMap use internal iteration #58730
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up, @timvermeulen!
The code itself looks right, and it's nice that it's actually shorter, I just have a small side request before merging.
count | ||
fn count(self) -> usize { | ||
let mut predicate = self.predicate; | ||
self.iter.map(|x| predicate(&x) as usize).sum() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
I added a few benchmarks, of which only
And here are the results of the existing
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Thanks, @timvermeulen! Great to see the other benchmarks made more representative too 🙂 @bors r+ rollup |
📌 Commit 88bd624 has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 88bd624 has been approved by |
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
…scottmcm Have all methods of Filter and FilterMap use internal iteration This PR changes `Filter::{next, next_back, count}` and `FilterMap::{next, next_back}` to all use internal iteration. The `next` and `next_back` methods are changed to directly forward to `try_for_each` and `try_rfold` respectively, using `Result` as the `Try` type. I think that's okay? Alternatively, I could change their implementations to use `LoopState` instead if there's any benefit in doing so. r? @scottmcm
Rollup of 14 pull requests Successful merges: - #58730 (Have all methods of Filter and FilterMap use internal iteration) - #58780 (ManuallyDrop != MaybeUninit) - #58782 (Replace `s` with `self` in docs for str methods taking self.) - #58785 (allow specifying attributes for tool lints) - #58802 (Ensure `record_layout_for_printing()` is inlined.) - #58821 (Fixed a syntax error in the pin docs) - #58830 (tidy: deny(rust_2018_idioms)) - #58832 (Revert switching to GCP on AppVeyor) - #58833 (tools/rustbook: deny(rust_2018_idioms)) - #58835 (tools/remote-test-{client,server}: deny(rust_2018_idioms)) - #58838 (Fix typo in Vec#resize_with documentation) - #58842 (Forbid duplicating Cargo as a dependency) - #58852 (Update toolchain to build NetBSD release) - #58865 (Fix C-variadic function printing)
This PR changes
Filter::{next, next_back, count}
andFilterMap::{next, next_back}
to all use internal iteration. Thenext
andnext_back
methods are changed to directly forward totry_for_each
andtry_rfold
respectively, usingResult
as theTry
type. I think that's okay? Alternatively, I could change their implementations to useLoopState
instead if there's any benefit in doing so.r? @scottmcm