-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
Changes from 1 commit
619003d
8334977
a907d9a
01af316
5057e3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks incorrect since this iterator can yield fewer items than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this should instead be:
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
#[stable(feature = "iter_arith_traits_result", since="1.16.0")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1188,6 +1188,11 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> { | |
None => None, | ||
} | ||
} | ||
|
||
#[inline] | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.iter.size_hint() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks incorrect since this iterator can yield fewer items than There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
let mut adapter = Adapter { iter: iter.into_iter(), found_none: false }; | ||
|
There was a problem hiding this comment.
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
char
s than it has inputu8
s. Seestd::str::Chars::size_hint
.There was a problem hiding this comment.
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 thenext()
implementation and assumed that meant a 1:1 correspondence.