diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-30 13:36:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-30 13:36:48 +0900 |
| commit | c26dd4d4140202283221c05758b1b1531b2fbb96 (patch) | |
| tree | c4a8d8ef3ee93f46e038f003775cd7da268d098d /library | |
| parent | 7fa991fb8545d8b03f0ab953770cb4fa08921abc (diff) | |
| parent | a623ea5301737507a8229c2ddae74b20f727bd1b (diff) | |
| download | rust-c26dd4d4140202283221c05758b1b1531b2fbb96.tar.gz rust-c26dd4d4140202283221c05758b1b1531b2fbb96.zip | |
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?
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/str/iter.rs | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 8b952eab294..83f484dc570 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -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] |
