未验证 提交 c26dd4d4 编写于 作者: Y Yuki Okushi 提交者: GitHub

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?
......@@ -47,12 +47,7 @@ fn next(&mut self) -> Option<char> {
#[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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册