Uh oh!
There was an error while loading. Please reload this page.
Fix std::ops::Range size_hint and ExactSizeIterator impls - #22065
Conversation
When self.start > self.end, these iterators simply return None, so we adjust the size_hint to just return zero in this case. Certain optimizations can be implemented in and outside libstd if we know we can trust the size_hint for all inputs to for example Range<usize>. This corrects the ExactSizeIterator implementations, which IMO were unsound and incorrect previously, since they allowed a range like (2..1) to return a size_hint of -1us in when debug assertions are turned off.
rust-highfive
commented
Feb 7, 2015
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
bluss
commented
Feb 7, 2015
Having correct .size_hint implementations is important. See ZipTrusted in itertools which implements fast and safe lockstep iteration for certain trusted iterators. ZipTrusted's iteration matches the best case of iterating two or more slices based on a precomputed common lower bound (benchmark numbers). It is a prototype for something that could be added to libstd later. |
Gankra
commented
Feb 7, 2015
@bors r+ 4f61e rollup |
Gankra
commented
Feb 7, 2015
Thanks! |
bluss
commented
Feb 7, 2015
Thanks for the review! |
bors
commented
Feb 9, 2015
⌛ Testing commit 4f61e16 with merge 45c3731... |
bors
commented
Feb 9, 2015
💔 Test failed - auto-win-64-nopt-t |
alexcrichton
commented
Feb 9, 2015
@bors: retry |
When self.start > self.end, these iterators simply return None, so we adjust the size_hint to just return zero in this case. Certain optimizations can be implemented in and outside libstd if we know we can trust the size_hint for all inputs to for example Range<usize>. This corrects the ExactSizeIterator implementations, which IMO were unsound and incorrect previously, since they allowed a range like (2..1) to return a size_hint of -1us in when debug assertions are turned off.
When self.start > self.end, these iterators simply return None, so we adjust the size_hint to just return zero in this case. Certain optimizations can be implemented in and outside libstd if we know we can trust the size_hint for all inputs to for example Range<usize>. This corrects the ExactSizeIterator implementations, which IMO were unsound and incorrect previously, since they allowed a range like (2..1) to return a size_hint of -1us in when debug assertions are turned off.
internal: Fix 1.95.0 Clippy
When self.start > self.end, these iterators simply return None,
so we adjust the size_hint to just return zero in this case.
Certain optimizations can be implemented in and outside libstd if we
know we can trust the size_hint for all inputs to for example
Range.
This corrects the ExactSizeIterator implementations, which IMO were
unsound and incorrect previously, since they allowed a range like (2..1)
to return a size_hint of -1us in when debug assertions are turned off.