mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-19 19:17:31 +00:00
Simplify by calling SliceOrd::compare
This commit is contained in:
parent
3bd6e46687
commit
ececbb2687
@ -2294,21 +2294,7 @@ impl<A> SlicePartialOrd<A> for [A]
|
|||||||
where A: Ord
|
where A: Ord
|
||||||
{
|
{
|
||||||
default fn partial_compare(&self, other: &[A]) -> Option<Ordering> {
|
default fn partial_compare(&self, other: &[A]) -> Option<Ordering> {
|
||||||
let l = cmp::min(self.len(), other.len());
|
Some(SliceOrd::compare(self, other))
|
||||||
|
|
||||||
// Slice to the loop iteration range to enable bound check
|
|
||||||
// elimination in the compiler
|
|
||||||
let lhs = &self[..l];
|
|
||||||
let rhs = &other[..l];
|
|
||||||
|
|
||||||
for i in 0..l {
|
|
||||||
match lhs[i].cmp(&rhs[i]) {
|
|
||||||
Ordering::Equal => (),
|
|
||||||
non_eq => return Some(non_eq),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.len().partial_cmp(&other.len())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user