From cc31397a2e8d720749d4c93ae5bf48a12d387a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 5 Sep 2017 11:52:49 +0200 Subject: [PATCH] style: Don't waste a whole selector map for each class / id in the document. It's just useless. --- .../invalidation/element/invalidation_map.rs | 23 +++++++------------ .../style/invalidation/element/invalidator.rs | 12 +++++++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs index 68da374ba9e..4a1a092a2aa 100644 --- a/components/style/invalidation/element/invalidation_map.rs +++ b/components/style/invalidation/element/invalidation_map.rs @@ -139,10 +139,10 @@ impl SelectorMapEntry for StateDependency { pub struct InvalidationMap { /// A map from a given class name to all the selectors with that class /// selector. - pub class_to_selector: MaybeCaseInsensitiveHashMap>, + pub class_to_selector: MaybeCaseInsensitiveHashMap>, /// A map from a given id to all the selectors with that ID in the /// stylesheets currently applying to the document. - pub id_to_selector: MaybeCaseInsensitiveHashMap>, + pub id_to_selector: MaybeCaseInsensitiveHashMap>, /// A map of all the state dependencies. pub state_affecting_selectors: SelectorMap, /// A map of other attribute affecting selectors. @@ -245,21 +245,21 @@ impl InvalidationMap { for class in compound_visitor.classes { self.class_to_selector .entry(class, quirks_mode) - .or_insert_with(SelectorMap::new) - .insert(Dependency { + .or_insert_with(SmallVec::new) + .push(Dependency { selector: selector.clone(), selector_offset: sequence_start, - }, quirks_mode); + }) } for id in compound_visitor.ids { self.id_to_selector .entry(id, quirks_mode) - .or_insert_with(SelectorMap::new) - .insert(Dependency { + .or_insert_with(SmallVec::new) + .push(Dependency { selector: selector.clone(), selector_offset: sequence_start, - }, quirks_mode); + }) } if !compound_visitor.state.is_empty() { @@ -299,14 +299,7 @@ impl InvalidationMap { let mut n = 0; n += self.class_to_selector.malloc_shallow_size_of_hash(malloc_enclosing_size_of); - for (_, val) in self.class_to_selector.iter() { - n += val.malloc_size_of_children(malloc_enclosing_size_of); - } - n += self.id_to_selector.malloc_shallow_size_of_hash(malloc_enclosing_size_of); - for (_, val) in self.id_to_selector.iter() { - n += val.malloc_size_of_children(malloc_enclosing_size_of); - } n += self.state_affecting_selectors.malloc_size_of_children(malloc_enclosing_size_of); diff --git a/components/style/invalidation/element/invalidator.rs b/components/style/invalidation/element/invalidator.rs index 00c3e3f8954..4d4ebff9717 100644 --- a/components/style/invalidation/element/invalidator.rs +++ b/components/style/invalidation/element/invalidator.rs @@ -792,20 +792,26 @@ impl<'a, 'b: 'a, E> InvalidationCollector<'a, 'b, E> let removed_id = self.removed_id; if let Some(ref id) = removed_id { if let Some(deps) = map.id_to_selector.get(id, quirks_mode) { - self.collect_dependencies_in_map(deps) + for dep in deps { + self.scan_dependency(dep, false); + } } } let added_id = self.added_id; if let Some(ref id) = added_id { if let Some(deps) = map.id_to_selector.get(id, quirks_mode) { - self.collect_dependencies_in_map(deps) + for dep in deps { + self.scan_dependency(dep, false); + } } } for class in self.classes_added.iter().chain(self.classes_removed.iter()) { if let Some(deps) = map.class_to_selector.get(class, quirks_mode) { - self.collect_dependencies_in_map(deps) + for dep in deps { + self.scan_dependency(dep, false); + } } }