Rollup merge of #81409 - gilescope:chars_count, r=joshtriplett
Slight simplification of chars().count() Slight simplification: No need to call len(), we can just count the number of non continuation bytes. I can't see any reason not to do this, can you?
This commit is contained in:
commit
c26dd4d414
@ -47,12 +47,7 @@ impl<'a> Iterator for Chars<'a> {
|
||||
#[inline]
|
||||
fn count(self) -> usize {
|
||||
// length in `char` is equal to the number of non-continuation bytes
|
||||
let bytes_len = self.iter.len();
|
||||
let mut cont_bytes = 0;
|
||||
for &byte in self.iter {
|
||||
cont_bytes += utf8_is_cont_byte(byte) as usize;
|
||||
}
|
||||
bytes_len - cont_bytes
|
||||
self.iter.filter(|&&byte| !utf8_is_cont_byte(byte)).count()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
x
Reference in New Issue
Block a user