mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
auto merge of #1574 : pcwalton/servo/cheat-before-after, r=SimonSapin
125% win on selector matching (!) r? @SimonSapin
This commit is contained in:
commit
e7aa20a36d
1 changed files with 9 additions and 0 deletions
|
@ -51,6 +51,8 @@ struct SelectorMap {
|
||||||
element_hash: HashMap<~str, ~[Rule]>,
|
element_hash: HashMap<~str, ~[Rule]>,
|
||||||
// For Rules that don't have ID, class, or element selectors.
|
// For Rules that don't have ID, class, or element selectors.
|
||||||
universal_rules: ~[Rule],
|
universal_rules: ~[Rule],
|
||||||
|
/// Whether this hash is empty.
|
||||||
|
empty: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectorMap {
|
impl SelectorMap {
|
||||||
|
@ -60,6 +62,7 @@ impl SelectorMap {
|
||||||
class_hash: HashMap::new(),
|
class_hash: HashMap::new(),
|
||||||
element_hash: HashMap::new(),
|
element_hash: HashMap::new(),
|
||||||
universal_rules: ~[],
|
universal_rules: ~[],
|
||||||
|
empty: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +75,10 @@ impl SelectorMap {
|
||||||
&self,
|
&self,
|
||||||
node: &N,
|
node: &N,
|
||||||
matching_rules_list: &mut ~[Rule]) {
|
matching_rules_list: &mut ~[Rule]) {
|
||||||
|
if self.empty {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// At the end, we're going to sort the rules that we added, so remember where we began.
|
// At the end, we're going to sort the rules that we added, so remember where we began.
|
||||||
let init_len = matching_rules_list.len();
|
let init_len = matching_rules_list.len();
|
||||||
node.with_element(|element: &E| {
|
node.with_element(|element: &E| {
|
||||||
|
@ -147,6 +154,8 @@ impl SelectorMap {
|
||||||
/// Insert rule into the correct hash.
|
/// Insert rule into the correct hash.
|
||||||
/// Order in which to try: id_hash, class_hash, element_hash, universal_rules.
|
/// Order in which to try: id_hash, class_hash, element_hash, universal_rules.
|
||||||
fn insert(&mut self, rule: Rule) {
|
fn insert(&mut self, rule: Rule) {
|
||||||
|
self.empty = false;
|
||||||
|
|
||||||
match SelectorMap::get_id_name(&rule) {
|
match SelectorMap::get_id_name(&rule) {
|
||||||
Some(id_name) => {
|
Some(id_name) => {
|
||||||
match self.id_hash.find_mut(&id_name) {
|
match self.id_hash.find_mut(&id_name) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue