Skip to content

Commit 37771d4

Browse files
committed
Specialize StepBy::nth
1 parent 3bd4af8 commit 37771d4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/iter/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,18 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
694694
(f(inner_hint.0), inner_hint.1.map(f))
695695
}
696696
}
697+
698+
#[inline]
699+
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
700+
if self.first_take {
701+
if n == 0 {
702+
self.first_take = false;
703+
return self.iter.next()
704+
}
705+
n -= 1;
706+
}
707+
self.iter.nth(n * self.step)
708+
}
697709
}
698710

699711
// StepBy can only make the iterator shorter, so the len will still fit.

0 commit comments

Comments
 (0)