Skip to content

Commit

Permalink
Upgrade implementation of StepBy<RangeInclusive<_>>.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Jul 13, 2018
1 parent d299f03 commit b6ea93e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/libcore/iter/mod.rs
Expand Up @@ -787,17 +787,19 @@ where
#[inline]
fn spec_next(&mut self) -> Option<Self::Item> {
self.first_take = false;
if !(self.iter.start <= self.iter.end) {
if self.iter.is_empty() {
self.iter.is_iterating = Some(false);
return None;
}
// add 1 to self.step to get original step size back
// it was decremented for the general case on construction
if let Some(n) = self.iter.start.add_usize(self.step+1) {
self.iter.is_iterating = Some(n <= self.iter.end);
let next = mem::replace(&mut self.iter.start, n);
Some(next)
} else {
let last = self.iter.start.replace_one();
self.iter.end.replace_zero();
let last = self.iter.start.clone();
self.iter.is_iterating = Some(false);
Some(last)
}
}
Expand Down

0 comments on commit b6ea93e

Please sign in to comment.