Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: Source/core/css/resolver/SharedStyleFinder.cpp

Issue 29633003: Avoid style sharing with mis-matched descendant selectors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();

Powered by Google App Engine
This is Rietveld 408576698