Skip to content

Commit 60acbd3

Browse files
committed
Optimize CharIndices::advance_by
`Chars::advance_by` is already optimized. Delegate to it.
1 parent f45d4ac commit 60acbd3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/src/str/iter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ impl<'a> Iterator for CharIndices<'a> {
200200
self.iter.count()
201201
}
202202

203+
#[inline]
204+
fn advance_by(&mut self, remainder: usize) -> Result<(), NonZero<usize>> {
205+
let pre_len = self.iter.iter.len();
206+
let res = self.iter.advance_by(remainder);
207+
let len = self.iter.iter.len();
208+
self.front_offset += pre_len - len;
209+
res
210+
}
211+
203212
#[inline]
204213
fn size_hint(&self) -> (usize, Option<usize>) {
205214
self.iter.size_hint()

0 commit comments

Comments
 (0)