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
Simplify Iterator::next
for GenericShunt
used in iter::try_process
#107674
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. Please see the contribution instructions for more information. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
This is a fairly standard way to not need to manually implement rust/library/core/src/iter/adapters/array_chunks.rs Lines 49 to 51 in 3de7d7f
There are lots of other ways it can be written, if any of these help you follow what it's doing: self.try_for_each(Err).err()
self.find(|_| true)
self.find_map(Some) but they're all using the same core idea, which is a loop that always returns the first value. And if you look at the callers of rust/library/core/src/iter/traits/accum.rs Lines 48 to 56 in a000811
So my instinct here is to stay with the concise code for now. That said, if you have some benchmarks showing that doing @rustbot author |
I tried as you said to compare the compiled code (old: https://rust.godbolt.org/z/K3WaKP4z7, new: https://rust.godbolt.org/z/cWjPj781r). With optimization level 3, the code in both versions is compiled into the same asm. The difference appears only when the optimization level is less than or equal to 1 and reaches 10%. That is, there should be an improvement only in compile time. Should I close the PR? |
The job Click to see the possible cause of the failure (guessed by this bot)
|
This pull request simplifies the iterator implementation for the GenericShunt structure used in iter::try_process. Although the old implementation commands respect and admiration, but:
In any case, feel free to just close this PR if you think it's redundant.
cc @scottmcm.
P.S. More explicit old code: