Skip to content

Commit

Permalink
Clarify logic on bytes:code units ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtribick committed Jul 21, 2023
1 parent e6fa5c1 commit f777339
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions library/core/src/str/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,10 @@ impl<'a> Iterator for EncodeUtf16<'a> {
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.chars.iter.len();
// The highest bytes:code units ratio occurs for 3-byte sequences, so
// use this to determine the lower bound for the hint. The lowest
// The highest bytes:code units ratio occurs for 3-byte sequences,
// since a 4-byte sequence results in 2 code units. The lower bound
// is therefore determined by assuming the remaining bytes contain as
// many 3-byte sequences as possible. The highest bytes:code units
// ratio is for 1-byte sequences, so use this for the upper bound.
// `(len + 2)` can't overflow, because we know that the `slice::Iter`
// belongs to a slice in memory which has a maximum length of
Expand Down

0 comments on commit f777339

Please sign in to comment.