Skip to content

Add ExactSizeIterator impls for Hash{Map, Set, Table} #20915

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 1 commit into from
Jan 12, 2015

Conversation

csouth3
Copy link
Contributor

@csouth3 csouth3 commented Jan 11, 2015

Since ExactSizeIterator was decoupled from DoubleEndedIterator, it's now more or less "free" to implement ExactSizeIterator for these iterators. Not sure if this is even something that we want, but it was quick and easy enough to do that I thought I'd open a PR for it and see.

This commit also changes the return types of all size_hint() impls in these files from (uint, Option<uint>) to (usize, Option<usize>) since I was already in there and it's a closely related change.

This commit also changes the return types of all `size_hint()` impls
in these files from (uint, Option<uint>) to (usize, Option<usize>).
@rust-highfive
Copy link
Contributor

r? @pcwalton

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

@csouth3
Copy link
Contributor Author

csouth3 commented Jan 11, 2015

r? @gankro

@rust-highfive rust-highfive assigned Gankra and unassigned pcwalton Jan 11, 2015
}
#[stable]
impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
#[inline] fn len(&self) -> usize { self.inner.len() }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is strictly necessary, but sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured I'd avoid the unnecessary size_hint() unwrap by just calling straight down, but these can be removed if desired.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the strictly more correct thing, although if T: ExactSize, then size_hint is probably trivially inlineable to discard the upper-bound creation. This is fine as is; we need a better story for impl forwarding anyway (but thanks for soldiering through all this in the interim!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem! And I'll be happy to bring this in line with impl forwarding conventions if and when we get them if this happens to run afoul of them.

bors added a commit that referenced this pull request Jan 12, 2015
Add ExactSizeIterator impls for Hash{Map, Set, Table}

Reviewed-by: Gankro
@bors bors merged commit c053387 into rust-lang:master Jan 12, 2015
@csouth3 csouth3 deleted the hash-iters branch January 12, 2015 02:28
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.

5 participants