1
Fork 0

Let's try the most idiomatic way.

This commit is contained in:
Giles Cope 2021-01-26 11:36:02 +00:00
parent 425a70a460
commit c07e5585b3
No known key found for this signature in database
GPG key ID: DF85161DAE0FF36B

View file

@ -47,11 +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 mut char_count = 0;
for &byte in self.iter {
char_count += !utf8_is_cont_byte(byte) as usize;
}
char_count
self.iter.map(|&byte| !utf8_is_cont_byte(byte) as usize).sum()
}
#[inline]