diff --git a/engine/core/css/ElementRuleCollector.cpp b/engine/core/css/ElementRuleCollector.cpp index 3a8267e90fc..c6b0c2640bc 100644 --- a/engine/core/css/ElementRuleCollector.cpp +++ b/engine/core/css/ElementRuleCollector.cpp @@ -72,15 +72,12 @@ void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro { if (!propertySet) return; - m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); - if (m_result.ranges.firstAuthorRule == -1) - m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; m_result.addMatchedProperties(propertySet); if (!isCacheable) m_result.isCacheable = false; } -void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, RuleRange& ruleRange, CascadeOrder cascadeOrder) +void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, CascadeOrder cascadeOrder) { ASSERT(matchRequest.ruleSet); ASSERT(m_context.element()); @@ -90,19 +87,19 @@ void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest // We need to collect the rules for id, class, tag, and everything else into a buffer and // then sort the buffer. if (element.hasID()) - collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForStyleResolution()), cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForStyleResolution()), cascadeOrder, matchRequest); if (element.isStyledElement() && element.hasClass()) { for (size_t i = 0; i < element.classNames().size(); ++i) - collectMatchingRulesForList(matchRequest.ruleSet->classRules(element.classNames()[i]), cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->classRules(element.classNames()[i]), cascadeOrder, matchRequest); } - collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName()), cascadeOrder, matchRequest, ruleRange); - collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName()), cascadeOrder, matchRequest); + collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), cascadeOrder, matchRequest); } -void ElementRuleCollector::collectMatchingHostRules(const MatchRequest& matchRequest, RuleRange& ruleRange, CascadeOrder cascadeOrder) +void ElementRuleCollector::collectMatchingHostRules(const MatchRequest& matchRequest, CascadeOrder cascadeOrder) { - collectMatchingRulesForList(matchRequest.ruleSet->hostRules(), cascadeOrder, matchRequest, ruleRange); + collectMatchingRulesForList(matchRequest.ruleSet->hostRules(), cascadeOrder, matchRequest); } void ElementRuleCollector::sortAndTransferMatchedRules() @@ -141,7 +138,7 @@ inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData) return matched; } -void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) +void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, CascadeOrder cascadeOrder, const MatchRequest& matchRequest) { StyleRule* rule = ruleData.rule(); if (ruleMatches(ruleData)) { @@ -150,11 +147,6 @@ void ElementRuleCollector::collectRuleIfMatches(const RuleData& ruleData, Cascad if (properties.isEmpty()) return; - // Update our first/last rule indices in the matched rules array. - ++ruleRange.lastRuleIndex; - if (ruleRange.firstRuleIndex == -1) - ruleRange.firstRuleIndex = ruleRange.lastRuleIndex; - // Add this rule to our list of matched rules. addMatchedRule(&ruleData, cascadeOrder, matchRequest.styleSheetIndex, matchRequest.styleSheet); } diff --git a/engine/core/css/ElementRuleCollector.h b/engine/core/css/ElementRuleCollector.h index 4da85d9b6b1..2156ffc7481 100644 --- a/engine/core/css/ElementRuleCollector.h +++ b/engine/core/css/ElementRuleCollector.h @@ -22,6 +22,7 @@ #ifndef SKY_ENGINE_CORE_CSS_ELEMENTRULECOLLECTOR_H_ #define SKY_ENGINE_CORE_CSS_ELEMENTRULECOLLECTOR_H_ +#include "sky/engine/core/css/RuleSet.h" #include "sky/engine/core/css/SelectorChecker.h" #include "sky/engine/core/css/resolver/ElementResolveContext.h" #include "sky/engine/core/css/resolver/MatchRequest.h" @@ -32,8 +33,6 @@ namespace blink { class CSSStyleSheet; -class RuleData; -class RuleSet; class ScopedStyleResolver; typedef unsigned CascadeOrder; @@ -94,23 +93,23 @@ public: MatchResult& matchedResult(); - void collectMatchingRules(const MatchRequest&, RuleRange&, CascadeOrder = ignoreCascadeOrder); - void collectMatchingHostRules(const MatchRequest&, RuleRange&, CascadeOrder cascadeOrder = ignoreCascadeOrder); + void collectMatchingRules(const MatchRequest&, CascadeOrder = ignoreCascadeOrder); + void collectMatchingHostRules(const MatchRequest&, CascadeOrder cascadeOrder = ignoreCascadeOrder); void sortAndTransferMatchedRules(); void clearMatchedRules(); void addElementStyleProperties(const StylePropertySet*, bool isCacheable = true); private: - void collectRuleIfMatches(const RuleData&, CascadeOrder, const MatchRequest&, RuleRange&); + void collectRuleIfMatches(const RuleData&, CascadeOrder, const MatchRequest&); template - void collectMatchingRulesForList(const RuleDataListType* rules, CascadeOrder cascadeOrder, const MatchRequest& matchRequest, RuleRange& ruleRange) + void collectMatchingRulesForList(const RuleDataListType* rules, CascadeOrder cascadeOrder, const MatchRequest& matchRequest) { if (!rules) return; for (typename RuleDataListType::const_iterator it = rules->begin(), end = rules->end(); it != end; ++it) - collectRuleIfMatches(*it, cascadeOrder, matchRequest, ruleRange); + collectRuleIfMatches(*it, cascadeOrder, matchRequest); } bool ruleMatches(const RuleData&); diff --git a/engine/core/css/resolver/MatchResult.cpp b/engine/core/css/resolver/MatchResult.cpp index 1abed72a18a..2432b0ff995 100644 --- a/engine/core/css/resolver/MatchResult.cpp +++ b/engine/core/css/resolver/MatchResult.cpp @@ -34,19 +34,10 @@ namespace blink { -MatchedProperties::MatchedProperties() -{ -} - -MatchedProperties::~MatchedProperties() -{ -} - void MatchResult::addMatchedProperties(const StylePropertySet* properties) { matchedProperties.grow(matchedProperties.size() + 1); - MatchedProperties& newProperties = matchedProperties.last(); - newProperties.properties = const_cast(properties); + matchedProperties.last() = const_cast(properties); } } // namespace blink diff --git a/engine/core/css/resolver/MatchResult.h b/engine/core/css/resolver/MatchResult.h index c1694b3bf32..10b8677f34f 100644 --- a/engine/core/css/resolver/MatchResult.h +++ b/engine/core/css/resolver/MatchResult.h @@ -23,8 +23,6 @@ #ifndef SKY_ENGINE_CORE_CSS_RESOLVER_MATCHRESULT_H_ #define SKY_ENGINE_CORE_CSS_RESOLVER_MATCHRESULT_H_ -#include "sky/engine/core/css/RuleSet.h" -#include "sky/engine/core/css/SelectorChecker.h" #include "sky/engine/platform/heap/Handle.h" #include "sky/engine/wtf/RefPtr.h" #include "sky/engine/wtf/Vector.h" @@ -33,71 +31,16 @@ namespace blink { class StylePropertySet; -struct RuleRange { - RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { } - int& firstRuleIndex; - int& lastRuleIndex; -}; - -struct MatchRanges { - MatchRanges() : firstUARule(-1), lastUARule(-1), firstAuthorRule(-1), lastAuthorRule(-1) { } - int firstUARule; - int lastUARule; - int firstAuthorRule; - int lastAuthorRule; - RuleRange UARuleRange() { return RuleRange(firstUARule, lastUARule); } - RuleRange authorRuleRange() { return RuleRange(firstAuthorRule, lastAuthorRule); } -}; - -struct MatchedProperties { - ALLOW_ONLY_INLINE_ALLOCATION(); -public: - MatchedProperties(); - ~MatchedProperties(); - - RefPtr properties; -}; - -} // namespace blink - -WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::MatchedProperties); - -namespace blink { - class MatchResult { STACK_ALLOCATED(); public: MatchResult() : isCacheable(true) { } - Vector matchedProperties; - MatchRanges ranges; + Vector, 64> matchedProperties; bool isCacheable; - void addMatchedProperties(const StylePropertySet* properties); + void addMatchedProperties(const StylePropertySet*); }; -inline bool operator==(const MatchRanges& a, const MatchRanges& b) -{ - return a.firstUARule == b.firstUARule - && a.lastUARule == b.lastUARule - && a.firstAuthorRule == b.firstAuthorRule - && a.lastAuthorRule == b.lastAuthorRule; -} - -inline bool operator!=(const MatchRanges& a, const MatchRanges& b) -{ - return !(a == b); -} - -inline bool operator==(const MatchedProperties& a, const MatchedProperties& b) -{ - return a.properties == b.properties; -} - -inline bool operator!=(const MatchedProperties& a, const MatchedProperties& b) -{ - return !(a == b); -} - } // namespace blink #endif // SKY_ENGINE_CORE_CSS_RESOLVER_MATCHRESULT_H_ diff --git a/engine/core/css/resolver/MatchedPropertiesCache.cpp b/engine/core/css/resolver/MatchedPropertiesCache.cpp index 4f68638b22e..edcf16f7c9c 100644 --- a/engine/core/css/resolver/MatchedPropertiesCache.cpp +++ b/engine/core/css/resolver/MatchedPropertiesCache.cpp @@ -38,7 +38,6 @@ namespace blink { void CachedMatchedProperties::set(const RenderStyle* style, const RenderStyle* parentStyle, const MatchResult& matchResult) { matchedProperties.appendVector(matchResult.matchedProperties); - ranges = matchResult.ranges; // Note that we don't cache the original RenderStyle instance. It may be further modified. // The RenderStyle in the cache is really just a holder for the substructures and never used as-is. @@ -76,8 +75,6 @@ const CachedMatchedProperties* MatchedPropertiesCache::find(unsigned hash, const if (matchResult.matchedProperties[i] != cacheItem->matchedProperties[i]) return 0; } - if (cacheItem->ranges != matchResult.ranges) - return 0; return cacheItem; } @@ -126,9 +123,9 @@ void MatchedPropertiesCache::sweep(Timer*) Cache::iterator end = m_cache.end(); for (; it != end; ++it) { CachedMatchedProperties* cacheItem = it->value.get(); - Vector& matchedProperties = cacheItem->matchedProperties; + Vector>& matchedProperties = cacheItem->matchedProperties; for (size_t i = 0; i < matchedProperties.size(); ++i) { - if (matchedProperties[i].properties->hasOneRef()) { + if (matchedProperties[i]->hasOneRef()) { toRemove.append(it->key); break; } diff --git a/engine/core/css/resolver/MatchedPropertiesCache.h b/engine/core/css/resolver/MatchedPropertiesCache.h index bbf056e48d0..7ad4f93d0e9 100644 --- a/engine/core/css/resolver/MatchedPropertiesCache.h +++ b/engine/core/css/resolver/MatchedPropertiesCache.h @@ -37,10 +37,8 @@ class RenderStyle; class StyleResolverState; class CachedMatchedProperties final { - public: - Vector matchedProperties; - MatchRanges ranges; + Vector> matchedProperties; RefPtr renderStyle; RefPtr parentRenderStyle; diff --git a/engine/core/css/resolver/ScopedStyleResolver.cpp b/engine/core/css/resolver/ScopedStyleResolver.cpp index 7688fed1484..6655bf3f023 100644 --- a/engine/core/css/resolver/ScopedStyleResolver.cpp +++ b/engine/core/css/resolver/ScopedStyleResolver.cpp @@ -112,19 +112,17 @@ const StyleRuleKeyframes* ScopedStyleResolver::keyframeStylesForAnimation(String void ScopedStyleResolver::collectMatchingAuthorRules(ElementRuleCollector& collector, CascadeOrder cascadeOrder) { - RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet(), m_authorStyleSheets[i].get(), i); - collector.collectMatchingRules(matchRequest, ruleRange, cascadeOrder); + collector.collectMatchingRules(matchRequest, cascadeOrder); } } void ScopedStyleResolver::collectMatchingHostRules(ElementRuleCollector& collector, CascadeOrder cascadeOrder) { - RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); for (size_t i = 0; i < m_authorStyleSheets.size(); ++i) { MatchRequest matchRequest(&m_authorStyleSheets[i]->contents()->ruleSet(), m_authorStyleSheets[i].get(), i); - collector.collectMatchingHostRules(matchRequest, ruleRange, cascadeOrder); + collector.collectMatchingHostRules(matchRequest, cascadeOrder); } } diff --git a/engine/core/css/resolver/StyleResolver.cpp b/engine/core/css/resolver/StyleResolver.cpp index e9d22f55918..c2e2b967bab 100644 --- a/engine/core/css/resolver/StyleResolver.cpp +++ b/engine/core/css/resolver/StyleResolver.cpp @@ -148,12 +148,10 @@ StyleResolver::~StyleResolver() void StyleResolver::matchRules(Element& element, ElementRuleCollector& collector) { collector.clearMatchedRules(); - collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult().matchedProperties.size() - 1; CascadeOrder cascadeOrder = 0; - RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); - collector.collectMatchingRules(MatchRequest(&defaultStyles()), ruleRange, ++cascadeOrder); + collector.collectMatchingRules(MatchRequest(&defaultStyles()), ++cascadeOrder); if (ShadowRoot* shadowRoot = element.shadowRoot()) shadowRoot->scopedStyleResolver().collectMatchingHostRules(collector, ++cascadeOrder); @@ -279,7 +277,7 @@ PassRefPtr StyleResolver::styleForKeyframe(Element* element, const // relevant one is animation-timing-function and we special-case that in // CSSAnimations.cpp bool inheritedOnly = false; - applyMatchedProperties(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); + applyMatchedProperties(state, result, false, inheritedOnly); // If our font got dirtied, go ahead and update it now. updateFont(state); @@ -289,7 +287,7 @@ PassRefPtr StyleResolver::styleForKeyframe(Element* element, const StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeightValue()); // Now do rest of the properties. - applyMatchedProperties(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); + applyMatchedProperties(state, result, false, inheritedOnly); loadPendingResources(state); @@ -522,19 +520,16 @@ void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper } template -void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inheritedOnly) +void StyleResolver::applyMatchedProperties(StyleResolverState& state, const MatchResult& matchResult, bool isImportant, bool inheritedOnly) { - if (startIndex == -1) - return; - for (int i = startIndex; i <= endIndex; ++i) { - const MatchedProperties& matchedProperties = matchResult.matchedProperties[i]; - applyProperties(state, matchedProperties.properties.get(), isImportant, inheritedOnly); + for (const RefPtr& properties : matchResult.matchedProperties) { + applyProperties(state, properties.get(), isImportant, inheritedOnly); } } -static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties, unsigned size) +static unsigned computeMatchedPropertiesHash(const RefPtr* properties, unsigned size) { - return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size); + return StringHasher::hashMemory(properties, sizeof(*properties) * size); } void StyleResolver::invalidateMatchedPropertiesCache() @@ -582,9 +577,8 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc // The order is (1) high-priority not important, (2) high-priority important, (3) normal not important // and (4) normal important. state.setLineHeightValue(0); - applyMatchedProperties(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly); - applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly); - applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); + applyMatchedProperties(state, matchResult, false, applyInheritedOnly); + applyMatchedProperties(state, matchResult, true, applyInheritedOnly); // If our font got dirtied, go ahead and update it now. updateFont(state); @@ -597,13 +591,9 @@ void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDescription() != state.style()->fontDescription()) applyInheritedOnly = false; - // Now do the normal priority UA properties. - applyMatchedProperties(state, matchResult, false, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); - // Now do the author and user normal priority properties and all the !important properties. - applyMatchedProperties(state, matchResult, false, matchResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyInheritedOnly); - applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly); - applyMatchedProperties(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); + applyMatchedProperties(state, matchResult, false, applyInheritedOnly); + applyMatchedProperties(state, matchResult, true, applyInheritedOnly); loadPendingResources(state); diff --git a/engine/core/css/resolver/StyleResolver.h b/engine/core/css/resolver/StyleResolver.h index 398da637df8..813b16009d6 100644 --- a/engine/core/css/resolver/StyleResolver.h +++ b/engine/core/css/resolver/StyleResolver.h @@ -120,7 +120,7 @@ private: template static inline bool isPropertyForPass(CSSPropertyID); template - void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly); + void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, bool inheritedOnly); template void applyProperties(StyleResolverState&, const StylePropertySet* properties, bool isImportant, bool inheritedOnly); template