-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix size_hint for EncodeUtf16 #113898
Fix size_hint for EncodeUtf16 #113898
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
library/core/src/str/iter.rs
Outdated
// long as the underlying iterator. | ||
(low, high.and_then(|n| n.checked_mul(2))) | ||
let len = self.chars.iter.len(); | ||
// The highest bytes:code units ratio occurs for 3-byte sequences, so |
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 think this could explicitly mention surrogates, something like "because a 4-byte sequence will map to 2 code units as a surrogate pair," so we're covering the prior misconception about the output being twice as long.
Everything else looks good to me!
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.
Added some extra details.
Thanks! @bors r+ |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#112490 (Remove `#[cfg(all())]` workarounds from `c_char`) - rust-lang#113252 (Update the tracking issue for `const_cstr_from_ptr`) - rust-lang#113442 (Allow limited access to `OsString` bytes) - rust-lang#113876 (fix docs & example for `std::os::unix::prelude::FileExt::write_at`) - rust-lang#113898 (Fix size_hint for EncodeUtf16) - rust-lang#113934 (Multibyte character removal in String::pop and String::remove doctests) r? `@ghost` `@rustbot` modify labels: rollup
More realistic upper and lower bounds, and handle the case where the iterator is located within a surrogate pair.
Resolves #113897