Chromium Code Reviews| Index: Source/core/css/resolver/SharedStyleFinder.cpp |
| diff --git a/Source/core/css/resolver/SharedStyleFinder.cpp b/Source/core/css/resolver/SharedStyleFinder.cpp |
| index a2969bf327f2d5412942178edc39876e520ab4b2..578f20570a17575981a6478a5b7306e223a75587 100644 |
| --- a/Source/core/css/resolver/SharedStyleFinder.cpp |
| +++ b/Source/core/css/resolver/SharedStyleFinder.cpp |
| @@ -270,6 +270,8 @@ bool SharedStyleFinder::canShareStyleWithElement(const ElementResolveContext& co |
| return false; |
| if (parentElementPreventsSharing(parent)) |
| return false; |
| + if (!candidateMatchesDescendantRules(context, element)) |
|
esprehn
2013/10/21 19:19:08
The hotest part of style sharing is matching the r
|
| + return false; |
| } |
| return true; |
| @@ -312,6 +314,22 @@ bool SharedStyleFinder::matchesRuleSet(const ElementResolveContext& context, Rul |
| return collector.hasAnyMatchingRules(ruleSet); |
| } |
| +bool SharedStyleFinder::candidateMatchesDescendantRules(const ElementResolveContext& context, Element* candidate) const |
| +{ |
| + if (!m_descendantRuleSet) |
| + return false; |
| + |
| + ElementResolveContext candidateContext(*candidate); |
| + |
| + ElementRuleCollector collector(context, m_styleResolver->selectorFilter()); |
| + ElementRuleCollector candidateCollector(candidateContext, m_styleResolver->selectorFilter()); |
| + int firstRuleIndex = -1, lastRuleIndex = -1; |
| + RuleRange ruleRange(firstRuleIndex, lastRuleIndex); |
| + collector.collectMatchingRules(MatchRequest(m_descendantRuleSet), ruleRange, SelectorChecker::StaysWithinTreeScope); |
| + candidateCollector.collectMatchingRules(MatchRequest(m_descendantRuleSet), ruleRange, SelectorChecker::StaysWithinTreeScope); |
| + return collector.matchedResult().ranges == candidateCollector.matchedResult().ranges; |
|
esprehn
2013/10/21 19:19:08
Matching rules like this is really expensive.
|
| +} |
| + |
| RenderStyle* SharedStyleFinder::locateSharedStyle(const ElementResolveContext& context) |
| { |
| STYLE_STATS_ADD_SEARCH(); |