Skip to content
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

Specialize StepBy::nth #47552

Merged
merged 6 commits into from
Jan 31, 2018
Merged

Specialize StepBy::nth #47552

merged 6 commits into from
Jan 31, 2018

Conversation

oberien
Copy link
Contributor

@oberien oberien commented Jan 18, 2018

This allows optimizations of implementations of the inner iterator's .nth method.

@rust-highfive
Copy link
Collaborator

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space before }.

@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2018
@shepmaster
Copy link
Member

Thanks @oberien ! We'll make sure to get you a first-class review from @Kimundi or another team member soon!

@kennytm
Copy link
Member

kennytm commented Jan 24, 2018

Review ping for you @Kimundi!

@kennytm kennytm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 31, 2018
@kennytm
Copy link
Member

kennytm commented Jan 31, 2018

Since @Kimundi haven't left any comment here, reassigning to another @rust-lang/libs team member.

r? @dtolnay

@rust-highfive rust-highfive assigned dtolnay and unassigned Kimundi Jan 31, 2018
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Jan 31, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 31, 2018

📌 Commit 4a0da4c has been approved by dtolnay

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 31, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Jan 31, 2018
Specialize StepBy::nth

This allows optimizations of implementations of the inner iterator's `.nth` method.
bors added a commit that referenced this pull request Jan 31, 2018
Rollup of 16 pull requests

- Successful merges: #47838, #47840, #47844, #47874, #47875, #47876, #47884, #47886, #47889, #47890, #47891, #47795, #47677, #47893, #47895, #47552
- Failed merges:
@bors bors merged commit 4a0da4c into rust-lang:master Jan 31, 2018
@bvinc
Copy link
Contributor

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
Copy link
Member

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 .step_by(2).nth(4) to inline and const fold.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants