optimize common case of previously seen simple selectors

This commit is contained in:
Connor Skees 2020-07-04 12:11:01 -04:00
parent 87b18e321f
commit ca861d488b

View File

@ -912,10 +912,17 @@ impl Extender {
for component in complex.components { for component in complex.components {
if let ComplexSelectorComponent::Compound(component) = component { if let ComplexSelectorComponent::Compound(component) = component {
for simple in component.components { for simple in component.components {
// PERF: we compute the hash twice, which isn't great, but we avoid a superfluous
// clone in cases where we have already seen a simple selector (common in
// scenarios in which there is a lot of nesting)
if let Some(entry) = self.selectors.get_mut(&simple) {
entry.insert(selector.clone())
} else {
self.selectors self.selectors
.entry(simple.clone()) .entry(simple.clone())
.or_insert_with(SelectorHashSet::new) .or_insert_with(SelectorHashSet::new)
.insert(selector.clone()); .insert(selector.clone());
}
if let SimpleSelector::Pseudo(Pseudo { if let SimpleSelector::Pseudo(Pseudo {
selector: Some(simple_selector), selector: Some(simple_selector),