Conversation
|
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. |
src/libcore/iter/mod.rs
Outdated
| } | ||
| 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 :)
src/libcore/iter/mod.rs
Outdated
| // overflow handling | ||
| loop { | ||
| let mul = n.checked_mul(step); | ||
| if unsafe { intrinsics::likely(mul.is_some())} { |
|
Review ping for you @Kimundi! |
|
@bors r+ |
|
📌 Commit 4a0da4c has been approved by |
Specialize StepBy::nth This allows optimizations of implementations of the inner iterator's `.nth` method.
|
I know I'm late. But does anyone else think that this function is rather large to be marked inline? |
|
@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.