Insert rules in SelectorMap manually to avoid unnecessary allocation.

This commit is contained in:
S Pradeep Kumar 2013-11-18 17:05:20 +09:00
parent df7ec2613b
commit 7d90cc01b6

View file

@ -138,19 +138,28 @@ impl SelectorMap {
// is required because Arc makes Rule non-copyable) // is required because Arc makes Rule non-copyable)
match SelectorMap::get_id_name(rule.clone()) { match SelectorMap::get_id_name(rule.clone()) {
Some(id_name) => { Some(id_name) => {
// TODO: Is this is a wasteful allocation of a list (~[rule])? match self.id_hash.find_mut(&id_name) {
self.id_hash.insert_or_update_with(id_name, Some(rules) => {
~[rule.clone()], rules.push(rule.clone());
|_, v| v.push(rule.clone())); return;
}
None => {}
}
self.id_hash.insert(id_name, ~[rule.clone()]);
return; return;
} }
None => {} None => {}
} }
match SelectorMap::get_class_name(rule.clone()) { match SelectorMap::get_class_name(rule.clone()) {
Some(class_name) => { Some(class_name) => {
self.class_hash.insert_or_update_with(class_name, match self.class_hash.find_mut(&class_name) {
~[rule.clone()], Some(rules) => {
|_, v| v.push(rule.clone())); rules.push(rule.clone());
return;
}
None => {}
}
self.class_hash.insert(class_name, ~[rule.clone()]);
return; return;
} }
None => {} None => {}
@ -158,9 +167,14 @@ impl SelectorMap {
match SelectorMap::get_element_name(rule.clone()) { match SelectorMap::get_element_name(rule.clone()) {
Some(element_name) => { Some(element_name) => {
self.element_hash.insert_or_update_with(element_name, match self.element_hash.find_mut(&element_name) {
~[rule.clone()], Some(rules) => {
|_, v| v.push(rule.clone())); rules.push(rule.clone());
return;
}
None => {}
}
self.element_hash.insert(element_name, ~[rule.clone()]);
return; return;
} }
None => {} None => {}