-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Implement size_hint on various sys iterators #49552
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
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 |
---|---|---|
|
@@ -192,6 +192,15 @@ impl<'a> Iterator for SplitPaths<'a> { | |
Some(super::os2path(&in_progress)) | ||
} | ||
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
// There will be at most N + 1 entries, where N is the number of | ||
// remaining semicolons. | ||
let data = self.data.clone(); | ||
let semicolons = data.filter(|b| b == (';' as u16)).count(); | ||
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. Hm, is it a good idea for the size_hint calculation to actually iterate over the data? Or am I misunderstanding what is happening here? 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 is definitely controversial / not obvious. My motivation to iterate over the data to calculate the size is because, in this case, we have a static guarantee that the thing being iterated over is in-memory, and that iterating over it will have no side-effects. Further, the iterator is over the number of entries in a directory, which is inherently bounded; and it's particularly common to collect the result of a dir entry iterator. |
||
|
||
(0, Some(semicolons + 1)) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
|
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.
Same question about iteration here.