Skip to content

Commit 328abfb

Browse files
committed
Slight simplification of chars().count()
1 parent 9a9477f commit 328abfb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/core/src/str/iter.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ impl<'a> Iterator for Chars<'a> {
4747
#[inline]
4848
fn count(self) -> usize {
4949
// 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;
50+
let mut char_count = 0;
5251
for &byte in self.iter {
53-
cont_bytes += utf8_is_cont_byte(byte) as usize;
52+
if !utf8_is_cont_byte(byte) {
53+
char_count += 1;
54+
}
5455
}
55-
bytes_len - cont_bytes
56+
char_count
5657
}
5758

5859
#[inline]

0 commit comments

Comments
 (0)