mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -7,7 +7,7 @@ use servo_util::range;
|
||||||
use servo_util::range::{Range, RangeIndex, EachIndex};
|
use servo_util::range::{Range, RangeIndex, EachIndex};
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
|
|
||||||
use std::cmp::PartialOrd;
|
use std::cmp::{Ordering, PartialOrd};
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::num::NumCast;
|
use std::num::NumCast;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -398,9 +398,9 @@ impl<'a> DetailedGlyphStore {
|
||||||
let mut mut_records : Vec<DetailedGlyphRecord> = unsorted_records;
|
let mut mut_records : Vec<DetailedGlyphRecord> = unsorted_records;
|
||||||
mut_records.sort_by(|a, b| {
|
mut_records.sort_by(|a, b| {
|
||||||
if a < b {
|
if a < b {
|
||||||
Less
|
Ordering::Less
|
||||||
} else {
|
} else {
|
||||||
Greater
|
Ordering::Greater
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let mut sorted_records = mut_records;
|
let mut sorted_records = mut_records;
|
||||||
|
|
|
@ -8,6 +8,7 @@ use platform::font_template::FontTemplateData;
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use servo_util::range::Range;
|
use servo_util::range::Range;
|
||||||
use servo_util::vec::{Comparator, FullBinarySearchMethods};
|
use servo_util::vec::{Comparator, FullBinarySearchMethods};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::slice::Items;
|
use std::slice::Items;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use text::glyph::{CharIndex, GlyphStore};
|
use text::glyph::{CharIndex, GlyphStore};
|
||||||
|
@ -42,11 +43,11 @@ struct CharIndexComparator;
|
||||||
impl Comparator<CharIndex,GlyphRun> for CharIndexComparator {
|
impl Comparator<CharIndex,GlyphRun> for CharIndexComparator {
|
||||||
fn compare(&self, key: &CharIndex, value: &GlyphRun) -> Ordering {
|
fn compare(&self, key: &CharIndex, value: &GlyphRun) -> Ordering {
|
||||||
if *key < value.range.begin() {
|
if *key < value.range.begin() {
|
||||||
Less
|
Ordering::Less
|
||||||
} else if *key >= value.range.end() {
|
} else if *key >= value.range.end() {
|
||||||
Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
Equal
|
Ordering::Equal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1161,6 +1161,7 @@ impl<K: Eq + Hash, V> FindPush<K, V> for HashMap<K, Vec<V>> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use super::{DeclarationBlock, Rule, SelectorMap};
|
use super::{DeclarationBlock, Rule, SelectorMap};
|
||||||
use selectors::LocalName;
|
use selectors::LocalName;
|
||||||
|
@ -1201,7 +1202,7 @@ mod tests {
|
||||||
let rules_list = get_mock_rules(&["a.intro", "img.sidebar"]);
|
let rules_list = get_mock_rules(&["a.intro", "img.sidebar"]);
|
||||||
let a = &rules_list[0][0].declarations;
|
let a = &rules_list[0][0].declarations;
|
||||||
let b = &rules_list[1][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.");
|
"The rule that comes later should win.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
//! In-place sorting.
|
//! In-place sorting.
|
||||||
|
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) -> Ordering) {
|
fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) -> Ordering) {
|
||||||
if right <= left {
|
if right <= left {
|
||||||
return
|
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];
|
let v: *mut T = &mut arr[right as uint];
|
||||||
loop {
|
loop {
|
||||||
i += 1;
|
i += 1;
|
||||||
while compare(&arr[i as uint], &*v) == Less {
|
while compare(&arr[i as uint], &*v) == Ordering::Less {
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
j -= 1;
|
j -= 1;
|
||||||
while compare(&*v, &arr[j as uint]) == Less {
|
while compare(&*v, &arr[j as uint]) == Ordering::Less {
|
||||||
if j == left {
|
if j == left {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -31,11 +33,11 @@ fn quicksort_helper<T>(arr: &mut [T], left: int, right: int, compare: fn(&T, &T)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
arr.swap(i as uint, j as uint);
|
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;
|
p += 1;
|
||||||
arr.swap(p as uint, i as uint)
|
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;
|
q -= 1;
|
||||||
arr.swap(j as uint, q as uint)
|
arr.swap(j as uint, q as uint)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
use collections::TreeMap;
|
use collections::TreeMap;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::comm::{Sender, channel, Receiver};
|
use std::comm::{Sender, channel, Receiver};
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::io::timer::sleep;
|
use std::io::timer::sleep;
|
||||||
|
@ -228,9 +229,9 @@ impl TimeProfiler {
|
||||||
for (&(ref category, ref meta), ref mut data) in self.buckets.iter_mut() {
|
for (&(ref category, ref meta), ref mut data) in self.buckets.iter_mut() {
|
||||||
data.sort_by(|a, b| {
|
data.sort_by(|a, b| {
|
||||||
if a < b {
|
if a < b {
|
||||||
Less
|
Ordering::Less
|
||||||
} else {
|
} else {
|
||||||
Greater
|
Ordering::Greater
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let data_len = data.len();
|
let data_len = data.len();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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)]
|
#[cfg(test)]
|
||||||
use std::fmt::Show;
|
use std::fmt::Show;
|
||||||
|
@ -47,9 +47,9 @@ impl<'a, T> FullBinarySearchMethods<T> for &'a [T] {
|
||||||
let midv = &self[mid];
|
let midv = &self[mid];
|
||||||
|
|
||||||
match cmp.compare(key, midv) {
|
match cmp.compare(key, midv) {
|
||||||
Greater => low = (mid as int) + 1,
|
Ordering::Greater => low = (mid as int) + 1,
|
||||||
Less => high = (mid as int) - 1,
|
Ordering::Less => high = (mid as int) - 1,
|
||||||
Equal => return Some(mid),
|
Ordering::Equal => return Some(mid),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -7,6 +7,7 @@ use eutil::slice_to_str;
|
||||||
use libc::{mod, size_t, c_int, c_ushort, c_void};
|
use libc::{mod, size_t, c_int, c_ushort, c_void};
|
||||||
use libc::types::os::arch::c95::wchar_t;
|
use libc::types::os::arch::c95::wchar_t;
|
||||||
use std::char;
|
use std::char;
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn cef_string_utf8_cmp(a: *const cef_string_utf8_t, b: *const cef_string_utf8_t) -> c_int {
|
pub extern "C" fn cef_string_utf8_cmp(a: *const cef_string_utf8_t, b: *const cef_string_utf8_t) -> c_int {
|
||||||
unsafe {
|
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]| {
|
slice::raw::buf_as_slice((*b).str as *const u8, (*b).length as uint, |bstr:&[u8]| {
|
||||||
match astr.cmp(bstr) {
|
match astr.cmp(bstr) {
|
||||||
Less => -1,
|
Ordering::Less => -1,
|
||||||
Equal => 0,
|
Ordering::Equal => 0,
|
||||||
Greater => 1
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int {
|
pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int {
|
||||||
unsafe {
|
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]| {
|
slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u16]| {
|
||||||
match astr.cmp(bstr) {
|
match astr.cmp(bstr) {
|
||||||
Less => -1,
|
Ordering::Less => -1,
|
||||||
Equal => 0,
|
Ordering::Equal => 0,
|
||||||
Greater => 1
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn cef_string_wide_cmp(a: *const cef_string_wide_t, b: *const cef_string_wide_t) -> c_int {
|
pub extern "C" fn cef_string_wide_cmp(a: *const cef_string_wide_t, b: *const cef_string_wide_t) -> c_int {
|
||||||
unsafe {
|
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]| {
|
slice::raw::buf_as_slice((*b).str as *const wchar_t, (*b).length as uint, |bstr:&[wchar_t]| {
|
||||||
match astr.cmp(bstr) {
|
match astr.cmp(bstr) {
|
||||||
Less => -1,
|
Ordering::Less => -1,
|
||||||
Equal => 0,
|
Ordering::Equal => 0,
|
||||||
Greater => 1
|
Ordering::Greater => 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue