Skip to content

libcore: Simplify Enumerate, Zip::next_back #16728

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

Closed
wants to merge 1 commit into from
Closed

libcore: Simplify Enumerate, Zip::next_back #16728

wants to merge 1 commit into from

Conversation

bluss
Copy link
Member

@bluss bluss commented Aug 24, 2014

Use ExactSize::len() and defer to its decisions about overly defensive
assertions. Remove the length double-check and simply put a failure
case if the Zip finds an uneven end in .next_back().

Fixing this up since I think I wrote this, and it's been known to
confuse rusties (PR #15886).

Use ExactSize::len() and defer to its decisions about overly defensive
assertions. Remove the length double-check and simply put a failure
case if the Zip finds an uneven end in .next_back().

Fixing this up since I think I wrote this, and it's been known to
confuse rusties (PR#15886).
assert!(a_sz == b_sz);
let a_sz = self.a.len();
let b_sz = self.b.len();
if a_sz != b_sz {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than two checks here, couldn't you just do one cmp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, strictly speaking you can just have the a_sz > b_sz check, because in the else branch if a_sz = b_sz, then the range is empty and the loop doesn't run.

Not sure what's the most efficient/readable here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the input, I don't know exactly either. But the evening out step should only happen once, and that's why I wanted a single comparison to exclude it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, good call!

@Gankra
Copy link
Contributor

Gankra commented Aug 24, 2014

👍 this significantly improves the code quality.

bors added a commit that referenced this pull request Aug 24, 2014
Use ExactSize::len() and defer to its decisions about overly defensive
assertions. Remove the length double-check and simply put a failure
case if the Zip finds an uneven end in .next_back().

Fixing this up since I think I wrote this, and it's been known to
confuse rusties (PR #15886).
@bors bors closed this Aug 24, 2014
@bluss bluss deleted the zip-next-back branch August 24, 2014 20:32
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants