Skip to content

Commit f777339

Browse files
committed
Clarify logic on bytes:code units ratio
1 parent e6fa5c1 commit f777339

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/core/src/str/iter.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,10 @@ impl<'a> Iterator for EncodeUtf16<'a> {
14401440
#[inline]
14411441
fn size_hint(&self) -> (usize, Option<usize>) {
14421442
let len = self.chars.iter.len();
1443-
// The highest bytes:code units ratio occurs for 3-byte sequences, so
1444-
// use this to determine the lower bound for the hint. The lowest
1443+
// The highest bytes:code units ratio occurs for 3-byte sequences,
1444+
// since a 4-byte sequence results in 2 code units. The lower bound
1445+
// is therefore determined by assuming the remaining bytes contain as
1446+
// many 3-byte sequences as possible. The highest bytes:code units
14451447
// ratio is for 1-byte sequences, so use this for the upper bound.
14461448
// `(len + 2)` can't overflow, because we know that the `slice::Iter`
14471449
// belongs to a slice in memory which has a maximum length of

0 commit comments

Comments
 (0)