about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Tribick <ajtribick@googlemail.com>2023-07-21 23:49:31 +0200
committerAndrew Tribick <ajtribick@googlemail.com>2023-07-21 23:49:31 +0200
commitf777339af3eac0c0226417d3b63d50cbfd42eef2 (patch)
treec2e13f5b68961da3c6aad0ffbe946ce0a4d42cad
parente6fa5c18b56806aff5525c67f851a250bd8089f7 (diff)
downloadrust-f777339af3eac0c0226417d3b63d50cbfd42eef2.tar.gz
rust-f777339af3eac0c0226417d3b63d50cbfd42eef2.zip
Clarify logic on bytes:code units ratio
-rw-r--r--library/core/src/str/iter.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index 133167a7067..cd16810c4dd 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -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