<!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>[164118] 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/164118">164118</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-02-14 12:47:12 -0800 (Fri, 14 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make code generation of the unoptimized pseudo classes separate
https://bugs.webkit.org/show_bug.cgi?id=128704

Reviewed by Andreas Kling.

Mapping the unoptimized selectors when generating the code was useful for debugging
but those cases are so common that looping over unoptimizedPseudoCheckers was more
costly than anticipated.

This patch moves the unoptimized pseudo selector in their own array to simplify code generation.

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoType):
(WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssjitSelectorCompilercpp">trunk/Source/WebCore/cssjit/SelectorCompiler.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (164117 => 164118)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-14 20:34:06 UTC (rev 164117)
+++ trunk/Source/WebCore/ChangeLog        2014-02-14 20:47:12 UTC (rev 164118)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-02-14  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        Make code generation of the unoptimized pseudo classes separate
+        https://bugs.webkit.org/show_bug.cgi?id=128704
+
+        Reviewed by Andreas Kling.
+
+        Mapping the unoptimized selectors when generating the code was useful for debugging
+        but those cases are so common that looping over unoptimizedPseudoCheckers was more
+        costly than anticipated.
+
+        This patch moves the unoptimized pseudo selector in their own array to simplify code generation.
+
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addPseudoType):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
+
</ins><span class="cx"> 2014-02-14  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement text-decoration-skip: auto
</span></span></pre></div>
<a id="trunkSourceWebCorecssjitSelectorCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (164117 => 164118)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2014-02-14 20:34:06 UTC (rev 164117)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2014-02-14 20:47:12 UTC (rev 164118)
</span><span class="lines">@@ -109,6 +109,7 @@
</span><span class="cx">     const AtomicString* id;
</span><span class="cx">     Vector&lt;const AtomicStringImpl*, 1&gt; classNames;
</span><span class="cx">     HashSet&lt;unsigned&gt; pseudoClasses;
</span><ins>+    Vector&lt;JSC::FunctionPtr&gt; unoptimizedPseudoClasses;
</ins><span class="cx">     Vector&lt;const CSSSelector*&gt; attributes;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -214,36 +215,72 @@
</span><span class="cx">     return std::max(a, b);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline FunctionType addPseudoType(CSSSelector::PseudoType type, HashSet&lt;unsigned&gt;&amp; pseudoClasses)
</del><ins>+static inline FunctionType addPseudoType(CSSSelector::PseudoType type, SelectorFragment&amp; pseudoClasses)
</ins><span class="cx"> {
</span><span class="cx">     switch (type) {
</span><del>-    case CSSSelector::PseudoAnyLink:
-        pseudoClasses.add(CSSSelector::PseudoLink);
-        return FunctionType::SimpleSelectorChecker;
</del><ins>+    // Unoptimized pseudo selector. They are just function call to a simple testing function.
</ins><span class="cx">     case CSSSelector::PseudoAutofill:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isAutofilled));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoChecked:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isChecked));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoDefault:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isDefaultButtonForForm));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoDisabled:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isDisabled));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoEnabled:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isEnabled));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoFocus:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(SelectorChecker::matchesFocusPseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoIndeterminate:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(shouldAppearIndeterminate));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoInvalid:
</span><del>-    case CSSSelector::PseudoLink:
</del><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isInvalid));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoOptional:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isOptionalFormControl));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoReadOnly:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(matchesReadOnlyPseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoReadWrite:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(matchesReadWritePseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoRequired:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isRequiredFormControl));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoValid:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(isValid));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx"> #if ENABLE(FULLSCREEN_API)
</span><span class="cx">     case CSSSelector::PseudoFullScreen:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(matchesFullScreenPseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx"> #endif
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     case CSSSelector::PseudoFutureCue:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(matchesFutureCuePseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx">     case CSSSelector::PseudoPastCue:
</span><ins>+        pseudoClasses.unoptimizedPseudoClasses.append(JSC::FunctionPtr(matchesPastCuePseudoClass));
+        return FunctionType::SimpleSelectorChecker;
</ins><span class="cx"> #endif
</span><del>-        pseudoClasses.add(type);
</del><ins>+
+    // Optimized pseudo selectors.
+    case CSSSelector::PseudoAnyLink:
+        pseudoClasses.pseudoClasses.add(CSSSelector::PseudoLink);
</ins><span class="cx">         return FunctionType::SimpleSelectorChecker;
</span><span class="cx"> 
</span><ins>+    case CSSSelector::PseudoLink:
+        pseudoClasses.pseudoClasses.add(type);
+        return FunctionType::SimpleSelectorChecker;
+
</ins><span class="cx">     default:
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="lines">@@ -283,7 +320,7 @@
</span><span class="cx">             fragment.classNames.append(selector-&gt;value().impl());
</span><span class="cx">             break;
</span><span class="cx">         case CSSSelector::PseudoClass:
</span><del>-            m_functionType = mostRestrictiveFunctionType(m_functionType, addPseudoType(selector-&gt;pseudoType(), fragment.pseudoClasses));
</del><ins>+            m_functionType = mostRestrictiveFunctionType(m_functionType, addPseudoType(selector-&gt;pseudoType(), fragment));
</ins><span class="cx">             if (m_functionType == FunctionType::CannotCompile)
</span><span class="cx">                 goto CannotHandleSelector;
</span><span class="cx">             break;
</span><span class="lines">@@ -860,40 +897,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-struct UnoptimizedPseudoChecker {
-    CSSSelector::PseudoType pseudoId;
-    bool (*testFunction)(const Element*);
-};
-
-template&lt;bool (*testFunction)(Element*)&gt;
-inline bool nonConstTestFunctionWrapper(const Element* element)
-{
-    return testFunction(const_cast&lt;Element*&gt;(element));
-}
-
-static const UnoptimizedPseudoChecker unoptimizedPseudoCheckers[] = {
-    { CSSSelector::PseudoAutofill, isAutofilled },
-    { CSSSelector::PseudoChecked, nonConstTestFunctionWrapper&lt;isChecked&gt; },
-    { CSSSelector::PseudoDefault, isDefaultButtonForForm },
-    { CSSSelector::PseudoDisabled, isDisabled },
-    { CSSSelector::PseudoEnabled, isEnabled },
-    { CSSSelector::PseudoIndeterminate, shouldAppearIndeterminate },
-    { CSSSelector::PseudoInvalid, isInvalid },
-    { CSSSelector::PseudoFocus, SelectorChecker::matchesFocusPseudoClass },
-    { CSSSelector::PseudoOptional, isOptionalFormControl },
-    { CSSSelector::PseudoReadOnly, matchesReadOnlyPseudoClass },
-    { CSSSelector::PseudoReadWrite, matchesReadWritePseudoClass },
-    { CSSSelector::PseudoRequired, isRequiredFormControl },
-    { CSSSelector::PseudoValid, isValid },
-#if ENABLE(FULLSCREEN_API)
-    { CSSSelector::PseudoFullScreen, matchesFullScreenPseudoClass },
-#endif
-#if ENABLE(VIDEO_TRACK)
-    { CSSSelector::PseudoFutureCue, matchesFutureCuePseudoClass },
-    { CSSSelector::PseudoPastCue, matchesPastCuePseudoClass },
-#endif
-};
-
</del><span class="cx"> void SelectorCodeGenerator::generateElementMatching(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp; fragment)
</span><span class="cx"> {
</span><span class="cx">     if (fragment.pseudoClasses.contains(CSSSelector::PseudoLink))
</span><span class="lines">@@ -902,12 +905,8 @@
</span><span class="cx">     if (fragment.tagName)
</span><span class="cx">         generateElementHasTagName(failureCases, *(fragment.tagName));
</span><span class="cx"> 
</span><del>-    if (!fragment.pseudoClasses.isEmpty()) {
-        for (unsigned i = 0; i &lt; WTF_ARRAY_LENGTH(unoptimizedPseudoCheckers); ++i) {
-            if (fragment.pseudoClasses.contains(unoptimizedPseudoCheckers[i].pseudoId))
-                generateElementFunctionCallTest(failureCases, unoptimizedPseudoCheckers[i].testFunction);
-        }
-    }
</del><ins>+    for (unsigned i = 0; i &lt; fragment.unoptimizedPseudoClasses.size(); ++i)
+        generateElementFunctionCallTest(failureCases, fragment.unoptimizedPseudoClasses[i]);
</ins><span class="cx"> 
</span><span class="cx">     generateElementDataMatching(failureCases, fragment);
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>