mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Use std::cmp::Ordering explicitly.
This commit is contained in:
parent
59bca2962c
commit
524966e3af
7 changed files with 44 additions and 38 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
//! In-place sorting.
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) -> Ordering) {
|
||||
if right <= left {
|
||||
return
|
||||
|
@ -17,11 +19,11 @@ fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T)
|
|||
let v: *mut T = &mut arr[right as uint];
|
||||
loop {
|
||||
i += 1;
|
||||
while compare(&arr[i as uint], &*v) == Less {
|
||||
while compare(&arr[i as uint], &*v) == Ordering::Less {
|
||||
i += 1
|
||||
}
|
||||
j -= 1;
|
||||
while compare(&*v, &arr[j as uint]) == Less {
|
||||
while compare(&*v, &arr[j as uint]) == Ordering::Less {
|
||||
if j == left {
|
||||
break
|
||||
}
|
||||
|
@ -31,11 +33,11 @@ fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T)
|
|||
break
|
||||
}
|
||||
arr.swap(i as uint, j as uint);
|
||||
if compare(&arr[i as uint], &*v) == Equal {
|
||||
if compare(&arr[i as uint], &*v) == Ordering::Equal {
|
||||
p += 1;
|
||||
arr.swap(p as uint, i as uint)
|
||||
}
|
||||
if compare(&*v, &arr[j as uint]) == Equal {
|
||||
if compare(&*v, &arr[j as uint]) == Ordering::Equal {
|
||||
q -= 1;
|
||||
arr.swap(j as uint, q as uint)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use collections::TreeMap;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cmp::Ordering;
|
||||
use std::comm::{Sender, channel, Receiver};
|
||||
use std::f64;
|
||||
use std::io::timer::sleep;
|
||||
|
@ -228,9 +229,9 @@ impl TimeProfiler {
|
|||
for (&(ref category, ref meta), ref mut data) in self.buckets.iter_mut() {
|
||||
data.sort_by(|a, b| {
|
||||
if a < b {
|
||||
Less
|
||||
Ordering::Less
|
||||
} else {
|
||||
Greater
|
||||
Ordering::Greater
|
||||
}
|
||||
});
|
||||
let data_len = data.len();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cmp::{PartialOrd, PartialEq};
|
||||
use std::cmp::{PartialOrd, PartialEq, Ordering};
|
||||
|
||||
#[cfg(test)]
|
||||
use std::fmt::Show;
|
||||
|
@ -47,9 +47,9 @@ impl<'a, T> FullBinarySearchMethods<T> for &'a [T] {
|
|||
let midv = &self[mid];
|
||||
|
||||
match cmp.compare(key, midv) {
|
||||
Greater => low = (mid as int) + 1,
|
||||
Less => high = (mid as int) - 1,
|
||||
Equal => return Some(mid),
|
||||
Ordering::Greater => low = (mid as int) + 1,
|
||||
Ordering::Less => high = (mid as int) - 1,
|
||||
Ordering::Equal => return Some(mid),
|
||||
}
|
||||
}
|
||||
return None;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue