<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[171059] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/171059">171059</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-07-13 14:51:16 -0700 (Sun, 13 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Remove SelectorCheckerFastPath from the style resolution algorithm
https://bugs.webkit.org/show_bug.cgi?id=134866

Reviewed by Antti Koivisto.

SelectorCheckerFastPath is now pure overhead because it can almost never match
if the CSS JIT was unable to compile.

* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::ruleMatches):
The &quot;pre-filter&quot; behind fastCheckableSelector had two parts:
1) Filtering the pseudoID.
2) Filtering on the rule hash.

The first part has been generalized (RuleDatacanMatchPseudoElement())
and moved to collectMatchingRulesForList(). 

(WebCore::ElementRuleCollector::collectMatchingRulesForList):
* css/RuleSet.cpp:
(WebCore::selectorCanMatchPseudoElement):
(WebCore::RuleData::RuleData):
(WebCore::RuleSet::addRegionRule):
(WebCore::RuleSet::addRulesFromSheet):
* css/RuleSet.h:
(WebCore::RuleData::canMatchPseudoElement):
(WebCore::RuleData::hasFastCheckableSelector): Deleted.
* css/StyleResolver.cpp:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssElementRuleCollectorcpp">trunk/Source/WebCore/css/ElementRuleCollector.cpp</a></li>
<li><a href="#trunkSourceWebCorecssRuleSetcpp">trunk/Source/WebCore/css/RuleSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssRuleSeth">trunk/Source/WebCore/css/RuleSet.h</a></li>
<li><a href="#trunkSourceWebCorecssStyleResolvercpp">trunk/Source/WebCore/css/StyleResolver.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (171058 => 171059)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-07-13 21:46:07 UTC (rev 171058)
+++ trunk/Source/WebCore/ChangeLog        2014-07-13 21:51:16 UTC (rev 171059)
</span><span class="lines">@@ -1,5 +1,35 @@
</span><span class="cx"> 2014-07-13  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
</span><span class="cx"> 
</span><ins>+        Remove SelectorCheckerFastPath from the style resolution algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=134866
+
+        Reviewed by Antti Koivisto.
+
+        SelectorCheckerFastPath is now pure overhead because it can almost never match
+        if the CSS JIT was unable to compile.
+
+        * css/ElementRuleCollector.cpp:
+        (WebCore::ElementRuleCollector::ruleMatches):
+        The &quot;pre-filter&quot; behind fastCheckableSelector had two parts:
+        1) Filtering the pseudoID.
+        2) Filtering on the rule hash.
+
+        The first part has been generalized (RuleDatacanMatchPseudoElement())
+        and moved to collectMatchingRulesForList(). 
+
+        (WebCore::ElementRuleCollector::collectMatchingRulesForList):
+        * css/RuleSet.cpp:
+        (WebCore::selectorCanMatchPseudoElement):
+        (WebCore::RuleData::RuleData):
+        (WebCore::RuleSet::addRegionRule):
+        (WebCore::RuleSet::addRulesFromSheet):
+        * css/RuleSet.h:
+        (WebCore::RuleData::canMatchPseudoElement):
+        (WebCore::RuleData::hasFastCheckableSelector): Deleted.
+        * css/StyleResolver.cpp:
+
+2014-07-13  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
</ins><span class="cx">         Remove an useless check from SelectorChecker
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=134868
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssElementRuleCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/ElementRuleCollector.cpp (171058 => 171059)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/ElementRuleCollector.cpp        2014-07-13 21:46:07 UTC (rev 171058)
+++ trunk/Source/WebCore/css/ElementRuleCollector.cpp        2014-07-13 21:51:16 UTC (rev 171059)
</span><span class="lines">@@ -39,7 +39,6 @@
</span><span class="cx"> #include &quot;InspectorInstrumentation.h&quot;
</span><span class="cx"> #include &quot;RenderRegion.h&quot;
</span><span class="cx"> #include &quot;SVGElement.h&quot;
</span><del>-#include &quot;SelectorCheckerFastPath.h&quot;
</del><span class="cx"> #include &quot;SelectorCompiler.h&quot;
</span><span class="cx"> #include &quot;StyleProperties.h&quot;
</span><span class="cx"> #include &quot;StyledElement.h&quot;
</span><span class="lines">@@ -273,15 +272,11 @@
</span><span class="cx"> 
</span><span class="cx"> inline bool ElementRuleCollector::ruleMatches(const RuleData&amp; ruleData)
</span><span class="cx"> {
</span><del>-    bool fastCheckableSelector = ruleData.hasFastCheckableSelector();
-    if (fastCheckableSelector) {
-        // We know this selector does not include any pseudo elements.
-        if (m_pseudoStyleRequest.pseudoId != NOPSEUDO)
-            return false;
-        // We know a sufficiently simple single part selector matches simply because we found it from the rule hash.
-        // This is limited to HTML only so we don't need to check the namespace.
-        if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() &amp;&amp; m_element.isHTMLElement())
-            return true;
</del><ins>+    // We know a sufficiently simple single part selector matches simply because we found it from the rule hash when filtering the RuleSet.
+    // This is limited to HTML only so we don't need to check the namespace (because of tag name match).
+    if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() &amp;&amp; m_element.isHTMLElement()) {
+        ASSERT_WITH_MESSAGE(m_pseudoStyleRequest.pseudoId == NOPSEUDO, &quot;If we match based on the rule hash while collecting for a particular pseudo element ID, we would add incorrect rules for that pseudo element ID. We should never end in ruleMatches() with a pseudo element if the ruleData cannot match any pseudo element.&quot;);
+        return true;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CSS_SELECTOR_JIT)
</span><span class="lines">@@ -319,16 +314,6 @@
</span><span class="cx">     }
</span><span class="cx"> #endif // ENABLE(CSS_SELECTOR_JIT)
</span><span class="cx"> 
</span><del>-    if (fastCheckableSelector) {
-        if (ruleData.selector()-&gt;m_match == CSSSelector::Tag &amp;&amp; !SelectorChecker::tagMatches(&amp;m_element, ruleData.selector()-&gt;tagQName()))
-            return false;
-        SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), &amp;m_element);
-        if (!selectorCheckerFastPath.matchesRightmostAttributeSelector())
-            return false;
-
-        return selectorCheckerFastPath.matches();
-    }
-
</del><span class="cx">     // Slow path.
</span><span class="cx">     SelectorChecker selectorChecker(m_element.document(), m_mode);
</span><span class="cx">     SelectorChecker::SelectorCheckingContext context(ruleData.selector(), &amp;m_element, SelectorChecker::VisitedMatchEnabled);
</span><span class="lines">@@ -346,6 +331,10 @@
</span><span class="cx"> 
</span><span class="cx">     for (unsigned i = 0, size = rules-&gt;size(); i &lt; size; ++i) {
</span><span class="cx">         const RuleData&amp; ruleData = rules-&gt;data()[i];
</span><ins>+
+        if (!ruleData.canMatchPseudoElement() &amp;&amp; m_pseudoStyleRequest.pseudoId != NOPSEUDO)
+            continue;
+
</ins><span class="cx">         if (m_canUseFastReject &amp;&amp; m_selectorFilter.fastRejectSelector&lt;RuleData::maximumIdentifierCount&gt;(ruleData.descendantSelectorIdentifierHashes()))
</span><span class="cx">             continue;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.cpp (171058 => 171059)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.cpp        2014-07-13 21:46:07 UTC (rev 171058)
+++ trunk/Source/WebCore/css/RuleSet.cpp        2014-07-13 21:51:16 UTC (rev 171059)
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx"> #include &quot;MediaQueryEvaluator.h&quot;
</span><span class="cx"> #include &quot;SecurityOrigin.h&quot;
</span><span class="cx"> #include &quot;SelectorChecker.h&quot;
</span><del>-#include &quot;SelectorCheckerFastPath.h&quot;
</del><span class="cx"> #include &quot;SelectorFilter.h&quot;
</span><span class="cx"> #include &quot;StyleResolver.h&quot;
</span><span class="cx"> #include &quot;StyleRule.h&quot;
</span><span class="lines">@@ -68,6 +67,25 @@
</span><span class="cx">     return selector.m_match == CSSSelector::Id || selector.m_match == CSSSelector::Class;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool selectorCanMatchPseudoElement(const CSSSelector&amp; rootSelector)
+{
+    const CSSSelector* selector = &amp;rootSelector;
+    do {
+        if (selector-&gt;matchesPseudoElement())
+            return true;
+
+        if (const CSSSelectorList* selectorList = selector-&gt;selectorList()) {
+            for (const CSSSelector* subSelector = selectorList-&gt;first(); subSelector; subSelector = CSSSelectorList::next(subSelector)) {
+                if (selectorCanMatchPseudoElement(*subSelector))
+                    return true;
+            }
+        }
+
+        selector = selector-&gt;tagHistory();
+    } while (selector);
+    return false;
+}
+
</ins><span class="cx"> static inline bool selectorListContainsAttributeSelector(const CSSSelector* selector)
</span><span class="cx"> {
</span><span class="cx">     const CSSSelectorList* selectorList = selector-&gt;selectorList();
</span><span class="lines">@@ -129,13 +147,13 @@
</span><span class="cx"> RuleData::RuleData(StyleRule* rule, unsigned selectorIndex, unsigned position, AddRuleFlags addRuleFlags)
</span><span class="cx">     : m_rule(rule)
</span><span class="cx">     , m_selectorIndex(selectorIndex)
</span><ins>+    , m_hasDocumentSecurityOrigin(addRuleFlags &amp; RuleHasDocumentSecurityOrigin)
</ins><span class="cx">     , m_position(position)
</span><del>-    , m_hasFastCheckableSelector((addRuleFlags &amp; RuleCanUseFastCheckSelector) &amp;&amp; SelectorCheckerFastPath::canUse(selector()))
</del><span class="cx">     , m_specificity(selector()-&gt;specificity())
</span><span class="cx">     , m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash(isSelectorMatchingHTMLBasedOnRuleHash(*selector()))
</span><ins>+    , m_canMatchPseudoElement(selectorCanMatchPseudoElement(*selector()))
</ins><span class="cx">     , m_containsUncommonAttributeSelector(WebCore::containsUncommonAttributeSelector(selector()))
</span><span class="cx">     , m_linkMatchType(SelectorChecker::determineLinkMatchType(selector()))
</span><del>-    , m_hasDocumentSecurityOrigin(addRuleFlags &amp; RuleHasDocumentSecurityOrigin)
</del><span class="cx">     , m_propertyWhitelistType(determinePropertyWhitelistType(addRuleFlags, selector()))
</span><span class="cx"> #if ENABLE(CSS_SELECTOR_JIT) &amp;&amp; CSS_SELECTOR_JIT_PROFILING
</span><span class="cx">     , m_compiledSelectorUseCount(0)
</span><span class="lines">@@ -291,7 +309,7 @@
</span><span class="cx">     // FIXME: Should this add other types of rules? (i.e. use addChildRules() directly?)
</span><span class="cx">     const Vector&lt;RefPtr&lt;StyleRuleBase&gt;&gt;&amp; childRules = regionRule-&gt;childRules();
</span><span class="cx">     AddRuleFlags addRuleFlags = hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState;
</span><del>-    addRuleFlags = static_cast&lt;AddRuleFlags&gt;(addRuleFlags | RuleCanUseFastCheckSelector | RuleIsInRegionRule);
</del><ins>+    addRuleFlags = static_cast&lt;AddRuleFlags&gt;(addRuleFlags | RuleIsInRegionRule);
</ins><span class="cx">     for (unsigned i = 0; i &lt; childRules.size(); ++i) {
</span><span class="cx">         StyleRuleBase* regionStylingRule = childRules[i].get();
</span><span class="cx">         if (regionStylingRule-&gt;isStyleRule())
</span><span class="lines">@@ -354,7 +372,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     bool hasDocumentSecurityOrigin = resolver &amp;&amp; resolver-&gt;document().securityOrigin()-&gt;canRequest(sheet-&gt;baseURL());
</span><del>-    AddRuleFlags addRuleFlags = static_cast&lt;AddRuleFlags&gt;((hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : 0) | RuleCanUseFastCheckSelector);
</del><ins>+    AddRuleFlags addRuleFlags = static_cast&lt;AddRuleFlags&gt;((hasDocumentSecurityOrigin ? RuleHasDocumentSecurityOrigin : 0));
</ins><span class="cx"> 
</span><span class="cx">     addChildRules(sheet-&gt;childRules(), medium, resolver, hasDocumentSecurityOrigin, addRuleFlags);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssRuleSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/RuleSet.h (171058 => 171059)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/RuleSet.h        2014-07-13 21:46:07 UTC (rev 171058)
+++ trunk/Source/WebCore/css/RuleSet.h        2014-07-13 21:51:16 UTC (rev 171059)
</span><span class="lines">@@ -36,8 +36,7 @@
</span><span class="cx"> enum AddRuleFlags {
</span><span class="cx">     RuleHasNoSpecialState         = 0,
</span><span class="cx">     RuleHasDocumentSecurityOrigin = 1,
</span><del>-    RuleCanUseFastCheckSelector   = 1 &lt;&lt; 1,
-    RuleIsInRegionRule            = 1 &lt;&lt; 2,
</del><ins>+    RuleIsInRegionRule            = 1 &lt;&lt; 1,
</ins><span class="cx"> };
</span><span class="cx">     
</span><span class="cx"> enum PropertyWhitelistType {
</span><span class="lines">@@ -66,7 +65,7 @@
</span><span class="cx">     const CSSSelector* selector() const { return m_rule-&gt;selectorList().selectorAt(m_selectorIndex); }
</span><span class="cx">     unsigned selectorIndex() const { return m_selectorIndex; }
</span><span class="cx"> 
</span><del>-    bool hasFastCheckableSelector() const { return m_hasFastCheckableSelector; }
</del><ins>+    bool canMatchPseudoElement() const { return m_canMatchPseudoElement; }
</ins><span class="cx">     bool hasRightmostSelectorMatchingHTMLBasedOnRuleHash() const { return m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash; }
</span><span class="cx">     bool containsUncommonAttributeSelector() const { return m_containsUncommonAttributeSelector; }
</span><span class="cx">     unsigned specificity() const { return m_specificity; }
</span><span class="lines">@@ -98,15 +97,15 @@
</span><span class="cx"> private:
</span><span class="cx">     RefPtr&lt;StyleRule&gt; m_rule;
</span><span class="cx">     unsigned m_selectorIndex : 13;
</span><ins>+    unsigned m_hasDocumentSecurityOrigin : 1;
</ins><span class="cx">     // This number was picked fairly arbitrarily. We can probably lower it if we need to.
</span><span class="cx">     // Some simple testing showed &lt;100,000 RuleData's on large sites.
</span><span class="cx">     unsigned m_position : 18;
</span><del>-    unsigned m_hasFastCheckableSelector : 1;
</del><span class="cx">     unsigned m_specificity : 24;
</span><span class="cx">     unsigned m_hasRightmostSelectorMatchingHTMLBasedOnRuleHash : 1;
</span><ins>+    unsigned m_canMatchPseudoElement : 1;
</ins><span class="cx">     unsigned m_containsUncommonAttributeSelector : 1;
</span><span class="cx">     unsigned m_linkMatchType : 2; //  SelectorChecker::LinkMatchMask
</span><del>-    unsigned m_hasDocumentSecurityOrigin : 1;
</del><span class="cx">     unsigned m_propertyWhitelistType : 2;
</span><span class="cx">     // Use plain array instead of a Vector to minimize memory overhead.
</span><span class="cx">     unsigned m_descendantSelectorIdentifierHashes[maximumIdentifierCount];
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleResolvercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleResolver.cpp (171058 => 171059)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleResolver.cpp        2014-07-13 21:46:07 UTC (rev 171058)
+++ trunk/Source/WebCore/css/StyleResolver.cpp        2014-07-13 21:51:16 UTC (rev 171059)
</span><span class="lines">@@ -109,7 +109,6 @@
</span><span class="cx"> #include &quot;SVGNames.h&quot;
</span><span class="cx"> #include &quot;SVGURIReference.h&quot;
</span><span class="cx"> #include &quot;SecurityOrigin.h&quot;
</span><del>-#include &quot;SelectorCheckerFastPath.h&quot;
</del><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;ShadowData.h&quot;
</span><span class="cx"> #include &quot;ShadowRoot.h&quot;
</span></span></pre>
</div>
</div>

</body>
</html>