Use std::cmp::Ordering explicitly.

This commit is contained in:
Ms2ger 2015-01-22 13:25:07 +01:00
parent 59bca2962c
commit 524966e3af
7 changed files with 44 additions and 38 deletions

View file

@ -7,7 +7,7 @@ use servo_util::range;
use servo_util::range::{Range, RangeIndex, EachIndex};
use servo_util::geometry::Au;
use std::cmp::PartialOrd;
use std::cmp::{Ordering, PartialOrd};
use std::iter::repeat;
use std::num::NumCast;
use std::mem;
@ -398,9 +398,9 @@ impl<'a> DetailedGlyphStore {
let mut mut_records : Vec<DetailedGlyphRecord> = unsorted_records;
mut_records.sort_by(|a, b| {
if a < b {
Less
Ordering::Less
} else {
Greater
Ordering::Greater
}
});
let mut sorted_records = mut_records;

View file

@ -8,6 +8,7 @@ use platform::font_template::FontTemplateData;
use servo_util::geometry::Au;
use servo_util::range::Range;
use servo_util::vec::{Comparator, FullBinarySearchMethods};
use std::cmp::Ordering;
use std::slice::Items;
use std::sync::Arc;
use text::glyph::{CharIndex, GlyphStore};
@ -42,11 +43,11 @@ struct CharIndexComparator;
impl Comparator<CharIndex,GlyphRun> for CharIndexComparator {
fn compare(&self, key: &CharIndex, value: &GlyphRun) -> Ordering {
if *key < value.range.begin() {
Less
Ordering::Less
} else if *key >= value.range.end() {
Greater
Ordering::Greater
} else {
Equal
Ordering::Equal
}
}
}

View file

@ -1161,6 +1161,7 @@ impl<K: Eq + Hash, V> FindPush<K, V> for HashMap<K, Vec<V>> {
#[cfg(test)]
mod tests {
use std::cmp::Ordering;
use std::sync::Arc;
use super::{DeclarationBlock, Rule, SelectorMap};
use selectors::LocalName;
@ -1201,7 +1202,7 @@ mod tests {
let rules_list = get_mock_rules(&["a.intro", "img.sidebar"]);
let a = &rules_list[0][0].declarations;
let b = &rules_list[1][0].declarations;
assert!((a.specificity, a.source_order).cmp(&(b.specificity, b.source_order)) == Less,
assert!((a.specificity, a.source_order).cmp(&(b.specificity, b.source_order)) == Ordering::Less,
"The rule that comes later should win.");
}

View file

@ -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)
}

View file

@ -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();

View file

@ -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;

View file

@ -7,6 +7,7 @@ use eutil::slice_to_str;
use libc::{mod, size_t, c_int, c_ushort, c_void};
use libc::types::os::arch::c95::wchar_t;
use std::char;
use std::cmp::Ordering;
use std::mem;
use std::ptr;
use std::slice;
@ -106,15 +107,15 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *
#[no_mangle]
pub extern "C" fn cef_string_utf8_cmp(a: *const cef_string_utf8_t, b: *const cef_string_utf8_t) -> c_int {
unsafe {
slice::raw::buf_as_slice((*a).str as *const u8, (*a).length as uint, |astr:&[u8]| {
slice::raw::buf_as_slice((*a).str as *const u8, (*a).length as uint, |astr:&[u8]| {
slice::raw::buf_as_slice((*b).str as *const u8, (*b).length as uint, |bstr:&[u8]| {
match astr.cmp(bstr) {
Less => -1,
Equal => 0,
Greater => 1
}
match astr.cmp(bstr) {
Ordering::Less => -1,
Ordering::Equal => 0,
Ordering::Greater => 1
}
})
})
})
}
}
@ -188,15 +189,15 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou
#[no_mangle]
pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int {
unsafe {
slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| {
slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| {
slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u16]| {
match astr.cmp(bstr) {
Less => -1,
Equal => 0,
Greater => 1
}
match astr.cmp(bstr) {
Ordering::Less => -1,
Ordering::Equal => 0,
Ordering::Greater => 1
}
})
})
})
}
}
@ -246,15 +247,15 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp
#[no_mangle]
pub extern "C" fn cef_string_wide_cmp(a: *const cef_string_wide_t, b: *const cef_string_wide_t) -> c_int {
unsafe {
slice::raw::buf_as_slice((*a).str as *const wchar_t, (*a).length as uint, |astr:&[wchar_t]| {
slice::raw::buf_as_slice((*a).str as *const wchar_t, (*a).length as uint, |astr:&[wchar_t]| {
slice::raw::buf_as_slice((*b).str as *const wchar_t, (*b).length as uint, |bstr:&[wchar_t]| {
match astr.cmp(bstr) {
Less => -1,
Equal => 0,
Greater => 1
}
match astr.cmp(bstr) {
Ordering::Less => -1,
Ordering::Equal => 0,
Ordering::Greater => 1
}
})
})
})
}
}