Map PartialORder in terms of Ord
Before:  315145
After:   315123
Savings:     22
@@ -68,8 +68,43 @@ impl CloneIntoHeap for &'static Map {
impl Eq for Map {}
impl Ord for Map {
+ /// > * Maps are compared by size, then by keys in ascending term order,
+ /// > then by values in key order. In the specific case of maps' key
+ /// > ordering, integers are always considered to be less than floats.
fn cmp(&self, other: &Self) -> Ordering {
- self.partial_cmp(other).unwrap()
+ match self.len().cmp(&other.len()) {
+ Equal => {
+ let self_key_vec = self.sorted_keys();
+ let other_key_vec = other.sorted_keys();
+
+ match self_key_vec.cmp(&other_key_vec) {
+ Equal => {
+ let self_inner = &self.inner;
+ let other_inner = &other.inner;
+ let mut final_ordering = Equal;
+
+ for key in self_key_vec {
+ match self_inner
+ .get(&key)
+ .unwrap()
+ .cmp(other_inner.get(&key).unwrap())
+ {
+ Equal => continue,
+ partial_ordering => {
+ final_ordering = partial_ordering;
+
+ break;
+ }
+ }
+ }
+
+ final_ordering
+ }
+ ordering => ordering,
+ }
+ }
+ ordering => ordering,
+ }
}
}
@@ -101,42 +136,7 @@ impl PartialEq for Map {
}
impl PartialOrd for Map {
- /// > * Maps are compared by size, then by keys in ascending term order,
- /// > then by values in key order. In the specific case of maps' key
- /// > ordering, integers are always considered to be less than floats.
fn partial_cmp(&self, other: &Map) -> Option<Ordering> {
- match self.len().partial_cmp(&other.len()) {
- Some(Equal) => {
- let self_key_vec = self.sorted_keys();
- let other_key_vec = other.sorted_keys();
-
- match self_key_vec.partial_cmp(&other_key_vec) {
- Some(Equal) => {
- let self_inner = &self.inner;
- let other_inner = &other.inner;
- let mut final_partial_ordering = Some(Equal);
-
- for key in self_key_vec {
- match self_inner
- .get(&key)
- .unwrap()
- .partial_cmp(other_inner.get(&key).unwrap())
- {
- Some(Equal) => continue,
- partial_ordering => {
- final_partial_ordering = partial_ordering;
-
- break;
- }
- }
- }
-
- final_partial_ordering
- }
- partial_ordering => partial_ordering,
- }
- }
- partial_ordering => partial_ordering,
- }
+ Some(self.cmp(other))
}
}
