Specialize StepBy::nth

This commit is contained in:
oberien 2018-01-18 20:49:32 +01:00
parent 3bd4af88be
commit 37771d42d7

View file

@ -694,6 +694,18 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
(f(inner_hint.0), inner_hint.1.map(f))
}
}
#[inline]
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
if self.first_take {
if n == 0 {
self.first_take = false;
return self.iter.next()
}
n -= 1;
}
self.iter.nth(n * self.step)
}
}
// StepBy can only make the iterator shorter, so the len will still fit.