-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
EscapeAscii no longer panics due to incorrect ExactSizeIterator #99913
Closed
softdevca
wants to merge
6
commits into
rust-lang:master
from
softdevca:escape_ascii_implements_exactsizeiterator
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6340b0
EscapeAscii no longer panics due to incorrect ExactSizeIterator
softdevca 603d0d6
Add end of file newline for tidy
softdevca e104c73
Add comma for tidy
softdevca d925efc
Length of iterator is remaining
softdevca 0728ed4
Merge branch 'rust-lang:master' into escape_ascii_implements_exactsiz…
softdevca 37a5ee9
EscapeAscii no longer implements ExactSizeIterator
softdevca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can't cache the value because len() must be updated every time an item is consumed from the iterator.
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.size_hint
This was also recently clarified for ExactsizeIterator, as you can see in the nightly docs
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.
Thank you for pointing out my oversight. I will recommit.
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.
Well, caching may still be cheaper than recomputing it every time, but you'll at least have to update the cached value every time an item is consumed.
But the problem with that is that it makes every call to
next()
more expensive, so which approach is beneficial depends on how often len() is called.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.
I feel caching is the better choice even with the extra overhead of an decrement each
next()
ornext_back()
and an extrausize
for eachEscapeAscii
. Caching avoids degenerate worst cases like users callinglen()
orsize_hint()
after each byte received from a slow source.It's unfortunately to even have to go through the source iterator more than once but there isn't any other way to implement
ExactSizeIterator
correctly and it can't be removed because it's been released in a stable version.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.
The stability policy does have exceptions for accidental stabilizations and critical bugfixes. So removing it is an option. The crater run in #99880 will tell us whether it's worthwhile taking that option.