Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 if (!tagName.isEmpty()) | 115 if (!tagName.isEmpty()) |
| 116 invalidationSet.addTagName(tagName); | 116 invalidationSet.addTagName(tagName); |
| 117 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it != classes.end(); ++it) { | 117 for (HashSet<AtomicString>::const_iterator it = classes.begin(); it != classes.end(); ++it) { |
| 118 invalidationSet.addClass(*it); | 118 invalidationSet.addClass(*it); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void RuleFeatureSet::addAttributeInASelector(const AtomicString& attributeName) | |
| 126 { | |
| 127 m_metadata.attrsInRules.add(attributeName); | |
| 128 } | |
| 129 | |
| 130 | |
| 125 void RuleFeatureSet::collectFeaturesFromRuleData(const RuleData& ruleData) | 131 void RuleFeatureSet::collectFeaturesFromRuleData(const RuleData& ruleData) |
| 126 { | 132 { |
| 127 bool foundSiblingSelector = false; | |
| 128 unsigned maxDirectAdjacentSelectors = 0; | |
| 129 for (const CSSSelector* selector = ruleData.selector(); selector; selector = selector->tagHistory()) { | |
| 130 collectFeaturesFromSelector(selector); | |
| 131 | 133 |
| 132 if (const CSSSelectorList* selectorList = selector->selectorList()) { | 134 FeatureMetadata metadata; |
| 133 for (const CSSSelector* subSelector = selectorList->first(); subSele ctor; subSelector = CSSSelectorList::next(subSelector)) { | 135 collectFeaturesFromSelector(ruleData.selector(), metadata); |
| 134 // FIXME: Shouldn't this be checking subSelector->isSiblingSelec tor()? | 136 m_metadata.add(metadata); |
|
esprehn
2014/01/23 01:13:29
Doesn't this mean we need to do more hash table it
chrishtr
2014/01/23 01:20:56
Yes. It'll have to do twice as many operations as
| |
| 135 if (!foundSiblingSelector && selector->isSiblingSelector()) | |
| 136 foundSiblingSelector = true; | |
| 137 if (subSelector->isDirectAdjacentSelector()) | |
| 138 maxDirectAdjacentSelectors++; | |
| 139 collectFeaturesFromSelector(subSelector); | |
| 140 } | |
| 141 } else { | |
| 142 if (!foundSiblingSelector && selector->isSiblingSelector()) | |
| 143 foundSiblingSelector = true; | |
| 144 if (selector->isDirectAdjacentSelector()) | |
| 145 maxDirectAdjacentSelectors++; | |
| 146 } | |
| 147 } | |
| 148 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) { | 137 if (RuntimeEnabledFeatures::targetedStyleRecalcEnabled()) { |
| 149 bool selectorUsesClassInvalidationSet = updateClassInvalidationSets(rule Data.selector()); | 138 bool selectorUsesClassInvalidationSet = updateClassInvalidationSets(rule Data.selector()); |
| 150 if (!selectorUsesClassInvalidationSet) { | 139 if (!selectorUsesClassInvalidationSet) { |
| 151 for (HashSet<AtomicString>::const_iterator it = classesInRules.begin (); it != classesInRules.end(); ++it) { | 140 for (HashSet<AtomicString>::const_iterator it = metadata.classesInRu les.begin(); it != metadata.classesInRules.end(); ++it) { |
| 152 DescendantInvalidationSet& invalidationSet = ensureClassInvalida tionSet(*it); | 141 DescendantInvalidationSet& invalidationSet = ensureClassInvalida tionSet(*it); |
| 153 invalidationSet.setWholeSubtreeInvalid(); | 142 invalidationSet.setWholeSubtreeInvalid(); |
| 154 } | 143 } |
| 155 } | 144 } |
| 156 } | 145 } |
| 157 setMaxDirectAdjacentSelectors(maxDirectAdjacentSelectors); | 146 if (metadata.foundSiblingSelector) |
| 158 if (foundSiblingSelector) | |
| 159 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex( ), ruleData.hasDocumentSecurityOrigin())); | 147 siblingRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex( ), ruleData.hasDocumentSecurityOrigin())); |
| 160 if (ruleData.containsUncommonAttributeSelector()) | 148 if (ruleData.containsUncommonAttributeSelector()) |
| 161 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.sele ctorIndex(), ruleData.hasDocumentSecurityOrigin())); | 149 uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.sele ctorIndex(), ruleData.hasDocumentSecurityOrigin())); |
| 162 } | 150 } |
| 163 | 151 |
| 164 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom icString& className) | 152 DescendantInvalidationSet& RuleFeatureSet::ensureClassInvalidationSet(const Atom icString& className) |
| 165 { | 153 { |
| 166 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN ame, 0); | 154 InvalidationSetMap::AddResult addResult = m_classInvalidationSets.add(classN ame, 0); |
| 167 if (addResult.isNewEntry) | 155 if (addResult.isNewEntry) |
| 168 addResult.iterator->value = DescendantInvalidationSet::create(); | 156 addResult.iterator->value = DescendantInvalidationSet::create(); |
| 169 return *addResult.iterator->value; | 157 return *addResult.iterator->value; |
| 170 } | 158 } |
| 171 | 159 |
| 172 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) | 160 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) |
| 173 { | 161 { |
| 174 if (selector->m_match == CSSSelector::Id) | 162 collectFeaturesFromSelector(selector, m_metadata); |
| 175 idsInRules.add(selector->value()); | 163 } |
| 176 else if (selector->m_match == CSSSelector::Class) | 164 |
| 177 classesInRules.add(selector->value()); | 165 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector, Ru leFeatureSet::FeatureMetadata& metadata) |
| 178 else if (selector->isAttributeSelector()) | 166 { |
| 179 attrsInRules.add(selector->attribute().localName()); | 167 for (; selector; selector = selector->tagHistory()) { |
| 180 switch (selector->pseudoType()) { | 168 if (selector->m_match == CSSSelector::Id) |
| 181 case CSSSelector::PseudoFirstLine: | 169 metadata.idsInRules.add(selector->value()); |
| 182 m_usesFirstLineRules = true; | 170 else if (selector->m_match == CSSSelector::Class) |
| 183 break; | 171 metadata.classesInRules.add(selector->value()); |
| 184 break; | 172 else if (selector->isAttributeSelector()) |
| 185 case CSSSelector::PseudoHost: | 173 metadata.attrsInRules.add(selector->attribute().localName()); |
| 186 collectFeaturesFromSelectorList(selector->selectorList()); | 174 |
| 187 break; | 175 if (selector->pseudoType() == CSSSelector::PseudoFirstLine) |
| 188 default: | 176 metadata.usesFirstLineRules = true; |
| 189 break; | 177 if (selector->isDirectAdjacentSelector()) |
| 178 metadata.maxDirectAdjacentSelectors++; | |
| 179 if (selector->isSiblingSelector()) | |
| 180 metadata.foundSiblingSelector = true; | |
| 181 | |
| 182 collectFeaturesFromSelectorList(selector->selectorList(), metadata); | |
| 190 } | 183 } |
| 191 } | 184 } |
| 192 | 185 |
| 193 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele ctorList) | 186 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele ctorList, RuleFeatureSet::FeatureMetadata& metadata) |
| 194 { | 187 { |
| 195 if (!selectorList) | 188 if (!selectorList) |
| 196 return; | 189 return; |
| 197 | 190 |
| 198 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(selector)) { | 191 for (const CSSSelector* selector = selectorList->first(); selector; selector = CSSSelectorList::next(selector)) { |
| 199 for (const CSSSelector* subSelector = selector; subSelector; subSelector = subSelector->tagHistory()) | 192 for (const CSSSelector* subSelector = selector; subSelector; subSelector = subSelector->tagHistory()) |
| 200 collectFeaturesFromSelector(subSelector); | 193 collectFeaturesFromSelector(subSelector, metadata); |
| 201 } | 194 } |
| 202 } | 195 } |
| 203 | 196 |
| 204 void RuleFeatureSet::add(const RuleFeatureSet& other) | 197 void RuleFeatureSet::FeatureMetadata::add(const FeatureMetadata& other) |
| 205 { | 198 { |
| 206 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it) { | 199 usesFirstLineRules = usesFirstLineRules || other.usesFirstLineRules; |
| 207 ensureClassInvalidationSet(it->key).combine(*it->value); | 200 maxDirectAdjacentSelectors = std::max(maxDirectAdjacentSelectors, other.maxD irectAdjacentSelectors); |
| 208 } | |
| 209 | 201 |
| 210 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); | 202 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); |
| 211 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it) | 203 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it != end; ++it) |
| 212 idsInRules.add(*it); | 204 idsInRules.add(*it); |
| 213 end = other.classesInRules.end(); | 205 end = other.classesInRules.end(); |
| 214 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin() ; it != end; ++it) | 206 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin() ; it != end; ++it) |
| 215 classesInRules.add(*it); | 207 classesInRules.add(*it); |
| 216 end = other.attrsInRules.end(); | 208 end = other.attrsInRules.end(); |
| 217 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin(); it != end; ++it) | 209 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin(); it != end; ++it) |
| 218 attrsInRules.add(*it); | 210 attrsInRules.add(*it); |
| 211 } | |
| 212 | |
| 213 void RuleFeatureSet::FeatureMetadata::clear() | |
| 214 { | |
| 215 | |
| 216 idsInRules.clear(); | |
| 217 classesInRules.clear(); | |
| 218 attrsInRules.clear(); | |
| 219 usesFirstLineRules = false; | |
| 220 foundSiblingSelector = false; | |
| 221 maxDirectAdjacentSelectors = 0; | |
| 222 } | |
| 223 | |
| 224 void RuleFeatureSet::add(const RuleFeatureSet& other) | |
| 225 { | |
| 226 for (InvalidationSetMap::const_iterator it = other.m_classInvalidationSets.b egin(); it != other.m_classInvalidationSets.end(); ++it) { | |
| 227 ensureClassInvalidationSet(it->key).combine(*it->value); | |
| 228 } | |
| 229 | |
| 230 m_metadata.add(other.m_metadata); | |
| 231 | |
| 219 siblingRules.append(other.siblingRules); | 232 siblingRules.append(other.siblingRules); |
| 220 uncommonAttributeRules.append(other.uncommonAttributeRules); | 233 uncommonAttributeRules.append(other.uncommonAttributeRules); |
| 221 m_usesFirstLineRules = m_usesFirstLineRules || other.m_usesFirstLineRules; | |
| 222 m_maxDirectAdjacentSelectors = std::max(m_maxDirectAdjacentSelectors, other. maxDirectAdjacentSelectors()); | |
| 223 } | 234 } |
| 224 | 235 |
| 225 void RuleFeatureSet::clear() | 236 void RuleFeatureSet::clear() |
| 226 { | 237 { |
| 227 idsInRules.clear(); | 238 m_metadata.clear(); |
| 228 classesInRules.clear(); | |
| 229 attrsInRules.clear(); | |
| 230 siblingRules.clear(); | 239 siblingRules.clear(); |
| 231 uncommonAttributeRules.clear(); | 240 uncommonAttributeRules.clear(); |
| 232 m_usesFirstLineRules = false; | |
| 233 m_maxDirectAdjacentSelectors = 0; | |
| 234 } | 241 } |
| 235 | 242 |
| 236 } // namespace WebCore | 243 } // namespace WebCore |
| OLD | NEW |