From 35b01cd324c5a491e079f8fd2a3685f9b252b28a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 19 Aug 2016 00:22:22 +0200 Subject: [PATCH] Sort rules by key in selector matching --- components/style/selector_matching.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index f6ea546e2e5..037f6522eb9 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -21,7 +21,6 @@ use selectors::parser::{Selector, SelectorImpl, SimpleSelector, LocalName, Compo use sink::Push; use smallvec::VecLike; use std::borrow::Borrow; -use std::cmp::Ordering; use std::collections::HashMap; use std::fmt; use std::hash::BuildHasherDefault; @@ -616,8 +615,8 @@ pub struct SelectorMap { } #[inline] -fn compare(a: &GenericDeclarationBlock, b: &GenericDeclarationBlock) -> Ordering { - (a.specificity, a.source_order).cmp(&(b.specificity, b.source_order)) +fn sort_by_key K, K: Ord>(v: &mut [T], f: F) { + sort_by(v, &|a, b| f(a).cmp(&f(b))) } impl SelectorMap { @@ -687,7 +686,8 @@ impl SelectorMap { relations); // Sort only the rules we just added. - sort_by(&mut matching_rules_list[init_len..], &compare); + sort_by_key(&mut matching_rules_list[init_len..], + |rule| (rule.specificity, rule.source_order)); } /// Append to `rule_list` all universal Rules (rules with selector `*|*`) in @@ -709,7 +709,8 @@ impl SelectorMap { } } - sort_by(&mut matching_rules_list[init_len..], &compare); + sort_by_key(&mut matching_rules_list[init_len..], + |rule| (rule.specificity, rule.source_order)); } fn get_matching_rules_from_hash(