Uh oh!
There was an error while loading. Please reload this page.
Specialize StepBy::nth - #47552
Conversation
rust-highfive
commented
Jan 18, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Kimundi (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. |
| } | ||
| n -= 1; | ||
| } | ||
| self.iter.nth(n * self.step) |
There was a problem hiding this comment.
Good change! ❤️
I think that this needs to handle overflow in the multiplication, though, since I could write (0u64..).step_by(0x10000).nth(0x10000) on a 32-bit machine, for example.
Also, tests?
There was a problem hiding this comment.
Tests are a good call, I found 2 off-by-ones while implementing them.
I added overflow behaviour, but it is pretty weighty. While I think that it shouldn't influence normal execution due to intrinsics::likely and branch prediction, I do think that it is pretty complicated code, which doesn't really add too much value. Anyway, now that it exists, I don't mind keeping it :)
| // overflow handling | ||
| loop { | ||
| let mul = n.checked_mul(step); | ||
| if unsafe { intrinsics::likely(mul.is_some())} { |
shepmaster
commented
Jan 20, 2018
kennytm
commented
Jan 24, 2018
Review ping for you @Kimundi! |
kennytm
commented
Jan 31, 2018
dtolnay
commented
Jan 31, 2018
@bors r+ |
bors
commented
Jan 31, 2018
📌 Commit 4a0da4c has been approved by |
Specialize StepBy::nth This allows optimizations of implementations of the inner iterator's `.nth` method.
bvinc
commented
Feb 7, 2018
I know I'm late. But does anyone else think that this function is rather large to be marked inline? |
scottmcm
commented
Feb 9, 2018
@bvinc Well, it's on a generic impl, so it'll be an inlining candidate regardless. And that's good in general, since you really want That said, it might be interesting to split out the overflow handling into a separate function, to make it easier for LLVM to inline the short easy normal path without the hard part. |
This allows optimizations of implementations of the inner iterator's
.nthmethod.