From 7af83dcd03b0de52bd67546b51b6a4f7ee98fd72 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Wed, 22 May 2019 23:51:09 -0400 Subject: [PATCH] Simplify CharIndices.next Char.len_utf8 is stable since #49698, making this a little easier to follow. --- src/libcore/str/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 0e8a2da3c110d..bf35541c28daa 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -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]