Skip to content

Implement some trivial size_hints for various iterators #49201

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

Merged
merged 5 commits into from
Mar 31, 2018

Conversation

Phlosioneer
Copy link
Contributor

This also implements ExactSizeIterator where applicable.

Addresses most of the Iterator traits mentioned in #23708.

I intend to do more, but I don't want to make the PR too large.

This also implements ExactSizeIterator where applicable.

Addresses most of the Iterator traits mentioned in rust-lang#23708.
@rust-highfive
Copy link
Contributor

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2018
@estebank
Copy link
Contributor

estebank commented Mar 20, 2018

LGTM, @rust-lang/libs anything I might be overlooking?


#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
Copy link
Contributor

Choose a reason for hiding this comment

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

This look incorrect. This iterator can yield fewer chars than it has input u8s. See std::str::Chars::size_hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right you are. I saw self.0.next().map(...) in the next() implementation and assumed that meant a 1:1 correspondence.

@@ -901,6 +901,10 @@ impl<I, T, E> Iterator for ResultShunt<I, E>
None => None,
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks incorrect since this iterator can yield fewer items than self.iter. Also this particular iterator is private and as far as can tell its size_hint is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this should instead be:

let (_, upper) = self.iter.size_hint();
(0, upper)

And I guess it's never used? I didn't really look; figuring out if it's used is harder than implementing it just-in-case, and the code around it could change.

I can remove it if you like.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it’s not used but this implementation is small enough that it’s probably fine to add it just in case it becomes used later.


#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks incorrect since this iterator can yield fewer items than self.iter. See std::iter::Filter::size_hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, forgot to commit this file. I'll commit and push it tomorrow.

@estebank
Copy link
Contributor

r? @SimonSapin

@rust-highfive rust-highfive assigned SimonSapin and unassigned estebank Mar 26, 2018
@SimonSapin
Copy link
Contributor

It looks like src/libcore/option.rs still needs to be changed/pushed.

(Please comment after pushing, I sometimes get email notifications for new commits but not always. I haven’t figured out in what cases.)

@Phlosioneer
Copy link
Contributor Author

Pushed my code for option.rs.

@SimonSapin
Copy link
Contributor

Thanks!

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 31, 2018

📌 Commit 5057e3c has been approved by SimonSapin

@bors bors 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 Mar 31, 2018
@bors
Copy link
Collaborator

bors commented Mar 31, 2018

⌛ Testing commit 5057e3c with merge 085c4b4...

bors added a commit that referenced this pull request Mar 31, 2018
Implement some trivial size_hints for various iterators

This also implements ExactSizeIterator where applicable.

Addresses most of the Iterator traits mentioned in #23708.

I intend to do more, but I don't want to make the PR too large.
@bors
Copy link
Collaborator

bors commented Mar 31, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: SimonSapin
Pushing 085c4b4 to master...

@bors bors merged commit 5057e3c into rust-lang:master Mar 31, 2018
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants