Changeset 125294 in webkit
- Timestamp:
- Aug 10, 2012 10:00:40 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r125293 r125294 1 2012-08-10 Andreas Kling <kling@webkit.org> 2 3 CSS: Shrink RuleData by storing selector as index rather than pointer. 4 <http://webkit.org/b/93712> 5 6 Reviewed by Antti Koivisto. 7 8 Pack the selector's index in the rule in the RuleData bitfield, effectively 9 shrinking each RuleData by 8 bytes. 10 11 * css/CSSSelectorList.h: 12 (WebCore::CSSSelectorList::selectorAt): 13 (WebCore::CSSSelectorList::indexOfNextSelectorAfter): 14 15 Add helpers to CSSSelectorList to iterate by index. 16 17 * css/StyleResolver.cpp: 18 (RuleData): 19 (WebCore::RuleData::selector): 20 (WebCore::RuleData::selectorIndex): 21 (SameSizeAsRuleData): 22 (RuleSet): 23 (WebCore::makeRuleSet): 24 (WebCore::StyleResolver::collectMatchingRulesForList): 25 * css/StyleResolver.h: 26 (WebCore::StyleResolver::RuleFeature::RuleFeature): 27 (RuleFeature): 28 29 Store selector indices instead of CSSSelector* pointers. 30 1 31 2012-08-10 Vineet Chaudhary <rgf748@motorola.com> 2 32 -
trunk/Source/WebCore/css/CSSSelectorList.h
r125252 r125294 49 49 static CSSSelector* next(CSSSelector*); 50 50 bool hasOneSelector() const { return m_selectorArray && !next(m_selectorArray); } 51 CSSSelector* selectorAt(size_t index) const { return &m_selectorArray[index]; } 52 53 size_t indexOfNextSelectorAfter(size_t index) const 54 { 55 CSSSelector* current = selectorAt(index); 56 current = next(current); 57 if (!current) 58 return notFound; 59 return current - m_selectorArray; 60 } 51 61 52 62 bool selectorsNeedNamespaceResolution(); -
trunk/Source/WebCore/css/StyleResolver.cpp
r125205 r125294 200 200 class RuleData { 201 201 public: 202 RuleData(StyleRule*, CSSSelector*, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule);202 RuleData(StyleRule*, unsigned selectorIndex, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule); 203 203 204 204 unsigned position() const { return m_position; } 205 205 StyleRule* rule() const { return m_rule; } 206 CSSSelector* selector() const { return m_selector; } 206 CSSSelector* selector() const { return m_rule->selectorList().selectorAt(m_selectorIndex); } 207 unsigned selectorIndex() const { return m_selectorIndex; } 207 208 208 209 bool hasFastCheckableSelector() const { return m_hasFastCheckableSelector; } … … 223 224 private: 224 225 StyleRule* m_rule; 225 CSSSelector* m_selector; 226 unsigned m_specificity; 226 unsigned m_selectorIndex : 12; 227 227 // This number was picked fairly arbitrarily. We can probably lower it if we need to. 228 228 // Some simple testing showed <100,000 RuleData's on large sites. 229 unsigned m_position : 24; 229 unsigned m_position : 20; 230 unsigned m_specificity : 24; 230 231 unsigned m_hasFastCheckableSelector : 1; 231 232 unsigned m_hasMultipartSelector : 1; … … 241 242 struct SameSizeAsRuleData { 242 243 void* a; 243 void* b; 244 unsigned c; 245 unsigned d; 246 unsigned e[4]; 244 uint64_t b; 245 unsigned c[4]; 247 246 }; 248 247 … … 259 258 260 259 void addStyleRule(StyleRule*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false); 261 void addRule(StyleRule*, CSSSelector*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);260 void addRule(StyleRule*, unsigned selectorIndex, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false); 262 261 void addPageRule(StyleRulePage*); 263 262 void addToRuleSet(AtomicStringImpl* key, AtomRuleMap&, const RuleData&); … … 482 481 OwnPtr<RuleSet> ruleSet = RuleSet::create(); 483 482 for (size_t i = 0; i < size; ++i) 484 ruleSet->addRule(rules[i].rule, rules[i].selector , rules[i].hasDocumentSecurityOrigin, false);483 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocumentSecurityOrigin, false); 485 484 ruleSet->shrinkToFit(); 486 485 return ruleSet.release(); … … 2496 2495 } 2497 2496 2498 RuleData::RuleData(StyleRule* rule, CSSSelector* selector, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule)2497 RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule) 2499 2498 : m_rule(rule) 2500 , m_selector(selector) 2501 , m_specificity(selector->specificity()) 2499 , m_selectorIndex(selectorIndex) 2502 2500 , m_position(position) 2503 , m_hasFastCheckableSelector(canUseFastCheckSelector && SelectorChecker::isFastCheckableSelector(selector)) 2504 , m_hasMultipartSelector(!!selector->tagHistory()) 2505 , m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector)) 2506 , m_containsUncommonAttributeSelector(WebCore::containsUncommonAttributeSelector(selector)) 2507 , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector)) 2501 , m_specificity(selector()->specificity()) 2502 , m_hasFastCheckableSelector(canUseFastCheckSelector && SelectorChecker::isFastCheckableSelector(selector())) 2503 , m_hasMultipartSelector(!!selector()->tagHistory()) 2504 , m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(selector())) 2505 , m_containsUncommonAttributeSelector(WebCore::containsUncommonAttributeSelector(selector())) 2506 , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector())) 2508 2507 , m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) 2509 2508 , m_isInRegionRule(inRegionRule) 2510 2509 { 2511 SelectorChecker::collectIdentifierHashes(m_selector, m_descendantSelectorIdentifierHashes, maximumIdentifierCount); 2510 ASSERT(m_position == position); 2511 ASSERT(m_selectorIndex == selectorIndex); 2512 SelectorChecker::collectIdentifierHashes(selector(), m_descendantSelectorIdentifierHashes, maximumIdentifierCount); 2512 2513 } 2513 2514 … … 2589 2590 } 2590 2591 if (foundSiblingSelector) 2591 features.siblingRules.append(StyleResolver::RuleFeature(ruleData.rule(), ruleData.selector (), ruleData.hasDocumentSecurityOrigin()));2592 features.siblingRules.append(StyleResolver::RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin())); 2592 2593 if (ruleData.containsUncommonAttributeSelector()) 2593 features.uncommonAttributeRules.append(StyleResolver::RuleFeature(ruleData.rule(), ruleData.selector (), ruleData.hasDocumentSecurityOrigin()));2594 features.uncommonAttributeRules.append(StyleResolver::RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin())); 2594 2595 } 2595 2596 … … 2604 2605 } 2605 2606 2606 void RuleSet::addRule(StyleRule* rule, CSSSelector* selector, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule)2607 { 2608 RuleData ruleData(rule, selector , m_ruleCount++, hasDocumentSecurityOrigin, canUseFastCheckSelector, inRegionRule);2607 void RuleSet::addRule(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool inRegionRule) 2608 { 2609 RuleData ruleData(rule, selectorIndex, m_ruleCount++, hasDocumentSecurityOrigin, canUseFastCheckSelector, inRegionRule); 2609 2610 collectFeaturesFromRuleData(m_features, ruleData); 2611 2612 CSSSelector* selector = ruleData.selector(); 2610 2613 2611 2614 if (selector->m_match == CSSSelector::Id) { … … 2749 2752 void RuleSet::addStyleRule(StyleRule* rule, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule) 2750 2753 { 2751 for ( CSSSelector* s = rule->selectorList().first(); s; s = CSSSelectorList::next(s))2752 addRule(rule, s , hasDocumentSecurityOrigin, canUseFastCheckSelector, isInRegionRule);2754 for (size_t selectorIndex = 0; selectorIndex != notFound; selectorIndex = rule->selectorList().indexOfNextSelectorAfter(selectorIndex)) 2755 addRule(rule, selectorIndex, hasDocumentSecurityOrigin, canUseFastCheckSelector, isInRegionRule); 2753 2756 } 2754 2757 -
trunk/Source/WebCore/css/StyleResolver.h
r124768 r125294 275 275 276 276 struct RuleFeature { 277 RuleFeature(StyleRule* rule, CSSSelector* selector, bool hasDocumentSecurityOrigin)277 RuleFeature(StyleRule* rule, unsigned selectorIndex, bool hasDocumentSecurityOrigin) 278 278 : rule(rule) 279 , selector (selector)279 , selectorIndex(selectorIndex) 280 280 , hasDocumentSecurityOrigin(hasDocumentSecurityOrigin) 281 281 { 282 282 } 283 283 StyleRule* rule; 284 CSSSelector* selector;284 unsigned selectorIndex; 285 285 bool hasDocumentSecurityOrigin; 286 286 };
Note: See TracChangeset
for help on using the changeset viewer.