Eliminate RuleRange.

In Sky there's no UA rules so we don't need to keep track of the
range of UA vs Author rules for running applyMatchedProperties later.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/863883002
This commit is contained in:
Elliott Sprehn 2015-01-20 19:50:35 -08:00
parent b05eec5f30
commit 5ebbdf3db6
9 changed files with 35 additions and 127 deletions

View File

@ -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);
}

View File

@ -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<typename RuleDataListType>
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&);

View File

@ -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<StylePropertySet*>(properties);
matchedProperties.last() = const_cast<StylePropertySet*>(properties);
}
} // namespace blink

View File

@ -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<StylePropertySet> 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, 64> matchedProperties;
MatchRanges ranges;
Vector<RefPtr<StylePropertySet>, 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_

View File

@ -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<MatchedPropertiesCache>*)
Cache::iterator end = m_cache.end();
for (; it != end; ++it) {
CachedMatchedProperties* cacheItem = it->value.get();
Vector<MatchedProperties>& matchedProperties = cacheItem->matchedProperties;
Vector<RefPtr<StylePropertySet>>& 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;
}

View File

@ -37,10 +37,8 @@ class RenderStyle;
class StyleResolverState;
class CachedMatchedProperties final {
public:
Vector<MatchedProperties> matchedProperties;
MatchRanges ranges;
Vector<RefPtr<StylePropertySet>> matchedProperties;
RefPtr<RenderStyle> renderStyle;
RefPtr<RenderStyle> parentRenderStyle;

View File

@ -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);
}
}

View File

@ -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<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const
// relevant one is animation-timing-function and we special-case that in
// CSSAnimations.cpp
bool inheritedOnly = false;
applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
applyMatchedProperties<HighPriorityProperties>(state, result, false, inheritedOnly);
// If our font got dirtied, go ahead and update it now.
updateFont(state);
@ -289,7 +287,7 @@ PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const
StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeightValue());
// Now do rest of the properties.
applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
applyMatchedProperties<LowPriorityProperties>(state, result, false, inheritedOnly);
loadPendingResources(state);
@ -522,19 +520,16 @@ void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper
}
template <StyleResolver::StyleApplicationPass pass>
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<pass>(state, matchedProperties.properties.get(), isImportant, inheritedOnly);
for (const RefPtr<StylePropertySet>& properties : matchResult.matchedProperties) {
applyProperties<pass>(state, properties.get(), isImportant, inheritedOnly);
}
}
static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties, unsigned size)
static unsigned computeMatchedPropertiesHash(const RefPtr<StylePropertySet>* 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<HighPriorityProperties>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, applyInheritedOnly);
applyMatchedProperties<HighPriorityProperties>(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<LowPriorityProperties>(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<LowPriorityProperties>(state, matchResult, false, matchResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, applyInheritedOnly);
applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, applyInheritedOnly);
loadPendingResources(state);

View File

@ -120,7 +120,7 @@ private:
template <StyleResolver::StyleApplicationPass pass>
static inline bool isPropertyForPass(CSSPropertyID);
template <StyleApplicationPass pass>
void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, bool inheritedOnly);
template <StyleApplicationPass pass>
void applyProperties(StyleResolverState&, const StylePropertySet* properties, bool isImportant, bool inheritedOnly);
template <StyleApplicationPass pass>