-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Override StepBy::{try_fold, try_rfold}
#64121
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
r? @scottmcm |
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 the PR! This definitely seems like one that needs try_fold (though I wish LLVM would just peel it). One minor change and it'll be good to go.
src/libcore/iter/adapters/mod.rs
Outdated
Some(x) => acc = f(acc, x)?, | ||
} | ||
} | ||
from_fn(|| self.iter.nth(self.step)).try_fold(acc, f) |
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.
Can you just use a while let Some(x) = self.iter.nth(self.step)
loop here instead? It'll do the same thing, but without introducing a new closure that would regress #62429.
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, I forgot about that. I turned the closures into functions instead, that should have the same benefits, correct? I figured this will make it easier to potentially undo these changes in the future.
@bors r+ rollup |
📌 Commit 78908f2 has been approved by |
… r=scottmcm Override `StepBy::{try_fold, try_rfold}` Previous PR: rust-lang#51435 The previous PR was closed in favor of rust-lang#51601, which was later reverted. I don't think these implementations will make it harder to specialize `StepBy<Range<_>>` later, so we should be able to land this without any consequences. This should fix rust-lang#57517 – in my benchmarks `iter` and `iter.step_by(1)` now perform equally well, provided internal iteration is used.
Previous PR: #51435
The previous PR was closed in favor of #51601, which was later reverted. I don't think these implementations will make it harder to specialize
StepBy<Range<_>>
later, so we should be able to land this without any consequences.This should fix #57517 – in my benchmarks
iter
anditer.step_by(1)
now perform equally well, provided internal iteration is used.