-
Notifications
You must be signed in to change notification settings - Fork 13.3k
override VecDeque
's Iter::try_fold
#57974
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Thanks! Can you be sure to add some tests to exercise this overriddent implementation in a few possible edge cases? |
c86e77b
to
7e22cb2
Compare
Sure thing. |
@bors: r+ Thanks! |
📌 Commit 7e22cb2 has been approved by |
…ichton override `VecDeque`'s `Iter::try_fold` This should improve performance (wherever it is used), but I haven't found the time to benchmark it yet.
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 |
Failed in rollup, #57982 (comment). @bors r- |
Oops, sorry about that. It was very late here when I added the tests. |
7e22cb2
to
b472a1a
Compare
b472a1a
to
b062b75
Compare
@bors: r+ |
📌 Commit b062b75 has been approved by |
override `VecDeque`'s `Iter::try_fold` This should improve performance (wherever it is used), but I haven't found the time to benchmark it yet.
☀️ Test successful - checks-travis, status-appveyor |
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, @llogiq!
{ | ||
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail); | ||
let accum = front.iter().try_fold(init, &mut f)?; | ||
back.iter().try_fold(accum, &mut 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.
I'm concerned about this -- if it short-circuits it's not going to resume from the correct place, since it's try_fold
ing on slice iterators and not updating the state of the self
iterator.
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.
I'd like to see a test like this one:
rust/src/libcore/tests/iter.rs
Lines 1990 to 1993 in 7164a9f
let a = [10, 20, 30, 40, 100, 60, 70, 80, 90]; | |
let mut iter = a.iter().rev(); | |
assert_eq!(iter.try_fold(0_i8, |acc, &x| acc.checked_add(x)), None); | |
assert_eq!(iter.next(), Some(&70)); |
Oh, oops, apparently I'm late to this :/ |
There's plenty of time to revert if that's necessary. :) |
You're right, @scottmcm. I'll do a follow-up PR to rectify this. |
Thanks, @llogiq! (As an aside, while you're at it, consider overriding |
I'm a bit unsure how to best proceed: Should I try to reinstate the pointer from the slice after the iteration? Or better change the iterator wholesale to a |
This should improve performance (wherever it is used), but I haven't found the time to benchmark it yet.