Skip to content

Commit

Permalink
Simplify CharIndices.next
Browse files Browse the repository at this point in the history
Char.len_utf8 is stable since rust-lang#49698, making this a little easier to follow.
  • Loading branch information
jridgewell committed May 23, 2019
1 parent dbfe70d commit 7af83dc
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,10 @@ impl<'a> Iterator for CharIndices<'a> {

#[inline]
fn next(&mut self) -> Option<(usize, char)> {
let pre_len = self.iter.iter.len();
match self.iter.next() {
None => None,
Some(ch) => {
let index = self.front_offset;
let len = self.iter.iter.len();
self.front_offset += pre_len - len;
Some((index, ch))
}
}
let ch = self.iter.next()?;
let index = self.front_offset;
self.front_offset += ch.len_utf8();
Some((index, ch))
}

#[inline]
Expand Down

0 comments on commit 7af83dc

Please sign in to comment.