Skip to content

Add/modify iterator size_hint()s #8604

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 2 commits into from

Conversation

lilyball
Copy link
Contributor

Implement size_hint() on the new std::vec Iterators.

Add or update size_hint() on std::iterator Iterators where appropriate.

r? @thestinger

@lilyball
Copy link
Contributor Author

When PR #8582 lands, RangeInclusive will need a size_hint() as well.

@@ -1504,6 +1522,9 @@ impl<A: Add<A, A> + Ord + Clone> Iterator<A> for Range<A> {
None
}
}

// FIXME: Implement 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.

I think tidy.py will yell about this, need to make an issue and add the number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh damn, so it does. I didn't realize.

Add size_hint() to a few Iterators that were missing it.

Update a couple of existing size_hint()s to use checked_add() instead of
saturating_add() for the upper bound.
if self.v.len() == 0 {
(0, Some(0))
} else {
let (n, rem) = self.v.len().div_rem(&self.size);
Copy link
Contributor

Choose a reason for hiding this comment

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

will this handle size == 0 properly? or do we not wind up in this iterator in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chunk_iter() has assert!(size != 0).

bors added a commit that referenced this pull request Aug 21, 2013
Implement `size_hint()` on the new std::vec Iterators.

Add or update `size_hint()` on std::iterator Iterators where appropriate.

r? @thestinger
@bors bors closed this Aug 21, 2013
xFrednet pushed a commit to xFrednet/rust that referenced this pull request May 21, 2022
…r=Alexendoo

Fix redundant_allocation warning for Rc<Box<str>>

changelog: [`redundant_allocation`] Fixes rust-lang#8604

Fixes false positives where a fat pointer with `str` type was made thin by another allocation, but that thinning allocation was marked as redundant
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.

4 participants