Simplify RangeInclusive::next[_back]
`match`ing on an `Option<Ordering>` seems cause some confusion for LLVM; switching to just using comparison operators removes a few jumps from the simple `for` loops I was trying.
This commit is contained in:
@@ -331,19 +331,17 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<A> {
|
||||
use cmp::Ordering::*;
|
||||
|
||||
match self.start.partial_cmp(&self.end) {
|
||||
Some(Less) => {
|
||||
if self.start <= self.end {
|
||||
if self.start < self.end {
|
||||
let n = self.start.add_one();
|
||||
Some(mem::replace(&mut self.start, n))
|
||||
},
|
||||
Some(Equal) => {
|
||||
} else {
|
||||
let last = self.start.replace_one();
|
||||
self.end.replace_zero();
|
||||
Some(last)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,19 +423,17 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
|
||||
impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<A> {
|
||||
use cmp::Ordering::*;
|
||||
|
||||
match self.start.partial_cmp(&self.end) {
|
||||
Some(Less) => {
|
||||
if self.start <= self.end {
|
||||
if self.start < self.end {
|
||||
let n = self.end.sub_one();
|
||||
Some(mem::replace(&mut self.end, n))
|
||||
},
|
||||
Some(Equal) => {
|
||||
} else {
|
||||
let last = self.end.replace_zero();
|
||||
self.start.replace_one();
|
||||
Some(last)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user