We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9a9477f commit 328abfbCopy full SHA for 328abfb
library/core/src/str/iter.rs
@@ -47,12 +47,13 @@ impl<'a> Iterator for Chars<'a> {
47
#[inline]
48
fn count(self) -> usize {
49
// length in `char` is equal to the number of non-continuation bytes
50
- let bytes_len = self.iter.len();
51
- let mut cont_bytes = 0;
+ let mut char_count = 0;
52
for &byte in self.iter {
53
- cont_bytes += utf8_is_cont_byte(byte) as usize;
+ if !utf8_is_cont_byte(byte) {
+ char_count += 1;
54
+ }
55
}
- bytes_len - cont_bytes
56
+ char_count
57
58
59
0 commit comments