Skip to content

Commit 7af83dc

Browse files
committed
Simplify CharIndices.next
Char.len_utf8 is stable since rust-lang#49698, making this a little easier to follow.
1 parent dbfe70d commit 7af83dc

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/libcore/str/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -663,16 +663,10 @@ impl<'a> Iterator for CharIndices<'a> {
663663

664664
#[inline]
665665
fn next(&mut self) -> Option<(usize, char)> {
666-
let pre_len = self.iter.iter.len();
667-
match self.iter.next() {
668-
None => None,
669-
Some(ch) => {
670-
let index = self.front_offset;
671-
let len = self.iter.iter.len();
672-
self.front_offset += pre_len - len;
673-
Some((index, ch))
674-
}
675-
}
666+
let ch = self.iter.next()?;
667+
let index = self.front_offset;
668+
self.front_offset += ch.len_utf8();
669+
Some((index, ch))
676670
}
677671

678672
#[inline]

0 commit comments

Comments
 (0)