<!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>[203439] trunk</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/203439">203439</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-19 18:29:25 -0700 (Tue, 19 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use getElementById for attribute matching if the attribute name is html's id
https://bugs.webkit.org/show_bug.cgi?id=159960

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; on 2016-07-19
Reviewed by Chris Dumez.

Source/WebCore:

Elliott Sprehn discovered YUI makes heavy uses of querySelector with [id=value]
(https://bugs.chromium.org/p/chromium/issues/detail?id=627242).

If we are not in quirks mode, IdForStyleResolution has the same value
as the Id attribute. We can use the same optimization for both cases.

Tests: fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html
       fast/selectors/id-attribute-querySelector-used-as-id-selector.html

* dom/SelectorQuery.cpp:
(WebCore::canBeUsedForIdFastPath):
(WebCore::findIdMatchingType):
(WebCore::SelectorDataList::SelectorDataList):
(WebCore::selectorForIdLookup):
(WebCore::filterRootById):

LayoutTests:

* fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt: Added.
* fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt: Added.
* fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html: Added.
* fast/selectors/id-attribute-querySelector-used-as-id-selector.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomSelectorQuerycpp">trunk/Source/WebCore/dom/SelectorQuery.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorexpectedtxt">trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorquirksexpectedtxt">trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorquirkshtml">trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorhtml">trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (203438 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-07-20 01:27:24 UTC (rev 203438)
+++ trunk/LayoutTests/ChangeLog        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-07-19  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        Use getElementById for attribute matching if the attribute name is html's id
+        https://bugs.webkit.org/show_bug.cgi?id=159960
+
+        Reviewed by Chris Dumez.
+
+        * fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt: Added.
+        * fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt: Added.
+        * fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html: Added.
+        * fast/selectors/id-attribute-querySelector-used-as-id-selector.html: Added.
+
</ins><span class="cx"> 2016-07-19  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Drop SVGElement.xmlbase attribute
</span></span></pre></div>
<a id="trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt (0 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-expected.txt        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+Verify the optimization transforming [id=value] into #value for querySelector.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Trivial Selector used as rightmost
+PASS document.querySelectorAll(&quot;[id=simple_unique]&quot;).length is 1
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated]&quot;).length is 3
+PASS document.querySelectorAll(&quot;[id=simple_duplicated]&quot;).length is 0
+Non-Trivial Selector used as rightmost
+PASS document.querySelectorAll(&quot;div[id=simple_unique][data-case]&quot;).length is 1
+PASS document.querySelectorAll(&quot;div[id=simple_Duplicated][data-case]&quot;).length is 3
+PASS document.querySelectorAll(&quot;div[id=simple_duplicated][data-case]&quot;).length is 0
+Trivial Selector used as ancestor filter
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt;&gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt;&gt; * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; *&quot;).length is 5
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt;&gt; * &gt; *&quot;).length is 0
+Non-Trivial Selector used as ancestor filter
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt;&gt; * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; *&quot;).length is 5
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; * &gt; *&quot;).length is 0
+Trivial Selector used as sibling filter
+PASS document.querySelectorAll(&quot;[id=simple_unique] + *&quot;).length is 1
+PASS document.querySelectorAll(&quot;[id=simple_unique] ~ *&quot;).length is 5
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] + *&quot;).length is 3
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] ~ *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] + *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] ~ *&quot;).length is 0
+Trivial Selector used as sibling of ancestor filter
+PASS document.querySelectorAll(&quot;[id=simple_unique] + * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_unique] ~ * &gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] + * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] ~ * &gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] + * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] ~ * &gt; *&quot;).length is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorquirksexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt (0 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks-expected.txt        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+Verify the optimization transforming [id=value] into #value for querySelector.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Trivial Selector used as rightmost
+PASS document.querySelectorAll(&quot;[id=simple_unique]&quot;).length is 1
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated]&quot;).length is 3
+PASS document.querySelectorAll(&quot;[id=simple_duplicated]&quot;).length is 0
+Non-Trivial Selector used as rightmost
+PASS document.querySelectorAll(&quot;div[id=simple_unique][data-case]&quot;).length is 1
+PASS document.querySelectorAll(&quot;div[id=simple_Duplicated][data-case]&quot;).length is 3
+PASS document.querySelectorAll(&quot;div[id=simple_duplicated][data-case]&quot;).length is 0
+Trivial Selector used as ancestor filter
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt;&gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=Ancestor_Unique] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_unique] &gt;&gt; * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; *&quot;).length is 5
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=ancestor_duplicated] &gt;&gt; * &gt; *&quot;).length is 0
+Non-Trivial Selector used as ancestor filter
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_unique][data-case] &gt;&gt; * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; *&quot;).length is 5
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt; * &gt;&gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt; * &gt;&gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; * &gt; *&quot;).length is 0
+Trivial Selector used as sibling filter
+PASS document.querySelectorAll(&quot;[id=simple_unique] + *&quot;).length is 1
+PASS document.querySelectorAll(&quot;[id=simple_unique] ~ *&quot;).length is 5
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] + *&quot;).length is 3
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] ~ *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] + *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] ~ *&quot;).length is 0
+Trivial Selector used as sibling of ancestor filter
+PASS document.querySelectorAll(&quot;[id=simple_unique] + * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_unique] ~ * &gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] + * &gt; *&quot;).length is 2
+PASS document.querySelectorAll(&quot;[id=simple_Duplicated] ~ * &gt; *&quot;).length is 4
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] + * &gt; *&quot;).length is 0
+PASS document.querySelectorAll(&quot;[id=simple_duplicated] ~ * &gt; *&quot;).length is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorquirkshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html (0 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -0,0 +1,101 @@
</span><ins>+&lt;html&gt;
+    &lt;head&gt;
+        &lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body&gt;
+        &lt;div class=&quot;display:none;&quot;&gt;
+            &lt;div id=&quot;simple_unique&quot; data-case=&quot;1&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;2&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;3&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;4&quot;&gt;&lt;/div&gt;
+
+            &lt;div id=&quot;Ancestor_Unique&quot; data-case=&quot;5&quot;&gt;
+                &lt;div data-case=&quot;6&quot;&gt;
+                    &lt;div data-case=&quot;7&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+                &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;8&quot;&gt;
+                    &lt;div data-case=&quot;9&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+            &lt;/div&gt;
+            &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;10&quot;&gt;
+                &lt;div data-case=&quot;11&quot;&gt;
+                    &lt;div data-case=&quot;12&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+                &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;13&quot;&gt;
+                    &lt;div data-case=&quot;14&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+            &lt;/div&gt;
+        &lt;/div&gt;
+        &lt;script&gt;
+            description(&quot;Verify the optimization transforming [id=value] into #value for querySelector.&quot;);
+
+            function test(selector, expectedCases)
+            {
+                shouldBe('document.querySelectorAll(&quot;' + selector + '&quot;).length', '' + expectedCases.length);
+                /*let queryResult = document.querySelectorAll(selector);
+                for (let i = 0; i &lt; queryResult.length; ++i) {
+                    shouldBeEqualToString('document.querySelectorAll(&quot;' + selector + '&quot;)[' + i + '].dataset.case', '' + expectedCases[i]);
+                }*/
+            }
+
+            debug(&quot;Trivial Selector used as rightmost&quot;);
+            test(&quot;[id=simple_unique]&quot;, [1]);
+            test(&quot;[id=simple_Duplicated]&quot;, [2, 3, 4]);
+            test(&quot;[id=simple_duplicated]&quot;, []);
+
+            debug(&quot;Non-Trivial Selector used as rightmost&quot;);
+            test(&quot;div[id=simple_unique][data-case]&quot;, [1]);
+            test(&quot;div[id=simple_Duplicated][data-case]&quot;, [2, 3, 4]);
+            test(&quot;div[id=simple_duplicated][data-case]&quot;, []);
+
+            debug(&quot;Trivial Selector used as ancestor filter&quot;);
+            test(&quot;[id=Ancestor_Unique] &gt;&gt; *&quot;, [6, 7, 8, 9]);
+            test(&quot;[id=Ancestor_Unique] &gt; * &gt;&gt; *&quot;, [7, 9]);
+            test(&quot;[id=Ancestor_Unique] &gt;&gt; * &gt; *&quot;, [7, 9]);
+            test(&quot;[id=ancestor_unique] &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_unique] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_unique] &gt;&gt; * &gt; *&quot;, []);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; *&quot;, [9, 11, 12, 13, 14]);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt; * &gt;&gt; *&quot;, [12, 14]);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; * &gt; *&quot;, [12, 14]);
+            test(&quot;[id=ancestor_duplicated] &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_duplicated] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_duplicated] &gt;&gt; * &gt; *&quot;, []);
+
+            debug(&quot;Non-Trivial Selector used as ancestor filter&quot;);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; *&quot;, [6, 7, 8, 9]);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt; * &gt;&gt; *&quot;, [7, 9]);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; * &gt; *&quot;, [7, 9]);
+            test(&quot;div[id=ancestor_unique][data-case] &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_unique][data-case] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_unique][data-case] &gt;&gt; * &gt; *&quot;, []);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; *&quot;, [9, 11, 12, 13, 14]);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt; * &gt;&gt; *&quot;, [12, 14]);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; * &gt; *&quot;, [12, 14]);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; * &gt; *&quot;, []);
+
+            debug(&quot;Trivial Selector used as sibling filter&quot;);
+            test(&quot;[id=simple_unique] + *&quot;, [2]);
+            test(&quot;[id=simple_unique] ~ *&quot;, [2, 3, 4, 5, 10]);
+            test(&quot;[id=simple_Duplicated] + *&quot;, [3, 4, 5]);
+            test(&quot;[id=simple_Duplicated] ~ *&quot;, [3, 4, 5, 10]);
+            test(&quot;[id=simple_duplicated] + *&quot;, []);
+            test(&quot;[id=simple_duplicated] ~ *&quot;, []);
+
+            debug(&quot;Trivial Selector used as sibling of ancestor filter&quot;);
+            test(&quot;[id=simple_unique] + * &gt; *&quot;, []);
+            test(&quot;[id=simple_unique] ~ * &gt; *&quot;, [6, 8, 11, 13]);
+            test(&quot;[id=simple_Duplicated] + * &gt; *&quot;, [6, 8]);
+            test(&quot;[id=simple_Duplicated] ~ * &gt; *&quot;, [6, 8, 11, 13]);
+            test(&quot;[id=simple_duplicated] + * &gt; *&quot;, []);
+            test(&quot;[id=simple_duplicated] ~ * &gt; *&quot;, []);
+        &lt;/script&gt;
+        &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsidattributequerySelectorusedasidselectorhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector.html (0 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/id-attribute-querySelector-used-as-id-selector.html        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -0,0 +1,102 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body&gt;
+        &lt;div class=&quot;display:none;&quot;&gt;
+            &lt;div id=&quot;simple_unique&quot; data-case=&quot;1&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;2&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;3&quot;&gt;&lt;/div&gt;
+            &lt;div id=&quot;simple_Duplicated&quot; data-case=&quot;4&quot;&gt;&lt;/div&gt;
+
+            &lt;div id=&quot;Ancestor_Unique&quot; data-case=&quot;5&quot;&gt;
+                &lt;div data-case=&quot;6&quot;&gt;
+                    &lt;div data-case=&quot;7&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+                &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;8&quot;&gt;
+                    &lt;div data-case=&quot;9&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+            &lt;/div&gt;
+            &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;10&quot;&gt;
+                &lt;div data-case=&quot;11&quot;&gt;
+                    &lt;div data-case=&quot;12&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+                &lt;div id=&quot;ANCESTOR_DUPLICATED&quot; data-case=&quot;13&quot;&gt;
+                    &lt;div data-case=&quot;14&quot;&gt;
+                    &lt;/div&gt;
+                &lt;/div&gt;
+            &lt;/div&gt;
+        &lt;/div&gt;
+        &lt;script&gt;
+            description(&quot;Verify the optimization transforming [id=value] into #value for querySelector.&quot;);
+
+            function test(selector, expectedCases)
+            {
+                shouldBe('document.querySelectorAll(&quot;' + selector + '&quot;).length', '' + expectedCases.length);
+                /*let queryResult = document.querySelectorAll(selector);
+                for (let i = 0; i &lt; queryResult.length; ++i) {
+                    shouldBeEqualToString('document.querySelectorAll(&quot;' + selector + '&quot;)[' + i + '].dataset.case', '' + expectedCases[i]);
+                }*/
+            }
+
+            debug(&quot;Trivial Selector used as rightmost&quot;);
+            test(&quot;[id=simple_unique]&quot;, [1]);
+            test(&quot;[id=simple_Duplicated]&quot;, [2, 3, 4]);
+            test(&quot;[id=simple_duplicated]&quot;, []);
+
+            debug(&quot;Non-Trivial Selector used as rightmost&quot;);
+            test(&quot;div[id=simple_unique][data-case]&quot;, [1]);
+            test(&quot;div[id=simple_Duplicated][data-case]&quot;, [2, 3, 4]);
+            test(&quot;div[id=simple_duplicated][data-case]&quot;, []);
+
+            debug(&quot;Trivial Selector used as ancestor filter&quot;);
+            test(&quot;[id=Ancestor_Unique] &gt;&gt; *&quot;, [6, 7, 8, 9]);
+            test(&quot;[id=Ancestor_Unique] &gt; * &gt;&gt; *&quot;, [7, 9]);
+            test(&quot;[id=Ancestor_Unique] &gt;&gt; * &gt; *&quot;, [7, 9]);
+            test(&quot;[id=ancestor_unique] &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_unique] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_unique] &gt;&gt; * &gt; *&quot;, []);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; *&quot;, [9, 11, 12, 13, 14]);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt; * &gt;&gt; *&quot;, [12, 14]);
+            test(&quot;[id=ANCESTOR_DUPLICATED] &gt;&gt; * &gt; *&quot;, [12, 14]);
+            test(&quot;[id=ancestor_duplicated] &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_duplicated] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;[id=ancestor_duplicated] &gt;&gt; * &gt; *&quot;, []);
+
+            debug(&quot;Non-Trivial Selector used as ancestor filter&quot;);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; *&quot;, [6, 7, 8, 9]);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt; * &gt;&gt; *&quot;, [7, 9]);
+            test(&quot;div[id=Ancestor_Unique][data-case] &gt;&gt; * &gt; *&quot;, [7, 9]);
+            test(&quot;div[id=ancestor_unique][data-case] &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_unique][data-case] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_unique][data-case] &gt;&gt; * &gt; *&quot;, []);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; *&quot;, [9, 11, 12, 13, 14]);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt; * &gt;&gt; *&quot;, [12, 14]);
+            test(&quot;div[id=ANCESTOR_DUPLICATED][data-case] &gt;&gt; * &gt; *&quot;, [12, 14]);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt; * &gt;&gt; *&quot;, []);
+            test(&quot;div[id=ancestor_duplicated][data-case] &gt;&gt; * &gt; *&quot;, []);
+
+            debug(&quot;Trivial Selector used as sibling filter&quot;);
+            test(&quot;[id=simple_unique] + *&quot;, [2]);
+            test(&quot;[id=simple_unique] ~ *&quot;, [2, 3, 4, 5, 10]);
+            test(&quot;[id=simple_Duplicated] + *&quot;, [3, 4, 5]);
+            test(&quot;[id=simple_Duplicated] ~ *&quot;, [3, 4, 5, 10]);
+            test(&quot;[id=simple_duplicated] + *&quot;, []);
+            test(&quot;[id=simple_duplicated] ~ *&quot;, []);
+
+            debug(&quot;Trivial Selector used as sibling of ancestor filter&quot;);
+            test(&quot;[id=simple_unique] + * &gt; *&quot;, []);
+            test(&quot;[id=simple_unique] ~ * &gt; *&quot;, [6, 8, 11, 13]);
+            test(&quot;[id=simple_Duplicated] + * &gt; *&quot;, [6, 8]);
+            test(&quot;[id=simple_Duplicated] ~ * &gt; *&quot;, [6, 8, 11, 13]);
+            test(&quot;[id=simple_duplicated] + * &gt; *&quot;, []);
+            test(&quot;[id=simple_duplicated] ~ * &gt; *&quot;, []);
+        &lt;/script&gt;
+        &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (203438 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-07-20 01:27:24 UTC (rev 203438)
+++ trunk/Source/WebCore/ChangeLog        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-07-19  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        Use getElementById for attribute matching if the attribute name is html's id
+        https://bugs.webkit.org/show_bug.cgi?id=159960
+
+        Reviewed by Chris Dumez.
+
+        Elliott Sprehn discovered YUI makes heavy uses of querySelector with [id=value]
+        (https://bugs.chromium.org/p/chromium/issues/detail?id=627242).
+
+        If we are not in quirks mode, IdForStyleResolution has the same value
+        as the Id attribute. We can use the same optimization for both cases.
+
+        Tests: fast/selectors/id-attribute-querySelector-used-as-id-selector-quirks.html
+               fast/selectors/id-attribute-querySelector-used-as-id-selector.html
+
+        * dom/SelectorQuery.cpp:
+        (WebCore::canBeUsedForIdFastPath):
+        (WebCore::findIdMatchingType):
+        (WebCore::SelectorDataList::SelectorDataList):
+        (WebCore::selectorForIdLookup):
+        (WebCore::filterRootById):
+
</ins><span class="cx"> 2016-07-19  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Drop SVGElement.xmlbase attribute
</span></span></pre></div>
<a id="trunkSourceWebCoredomSelectorQuerycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/SelectorQuery.cpp (203438 => 203439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/SelectorQuery.cpp        2016-07-20 01:27:24 UTC (rev 203438)
+++ trunk/Source/WebCore/dom/SelectorQuery.cpp        2016-07-20 01:29:25 UTC (rev 203439)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011, 2013, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011, 2013, 2014, 2016 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2014 Yusuke Suzuki &lt;utatane.tea@gmail.com&gt;
</span><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CSSParser.h&quot;
</span><span class="cx"> #include &quot;ElementDescendantIterator.h&quot;
</span><ins>+#include &quot;HTMLNames.h&quot;
</ins><span class="cx"> #include &quot;SelectorChecker.h&quot;
</span><span class="cx"> #include &quot;StaticNodeList.h&quot;
</span><span class="cx"> #include &quot;StyledElement.h&quot;
</span><span class="lines">@@ -53,11 +54,17 @@
</span><span class="cx">     Filter
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+static bool canBeUsedForIdFastPath(const CSSSelector&amp; selector)
+{
+    return selector.match() == CSSSelector::Id
+        || (selector.match() == CSSSelector::Exact &amp;&amp; selector.attribute() == HTMLNames::idAttr &amp;&amp; !selector.attributeValueMatchingIsCaseInsensitive());
+}
+
</ins><span class="cx"> static IdMatchingType findIdMatchingType(const CSSSelector&amp; firstSelector)
</span><span class="cx"> {
</span><span class="cx">     bool inRightmost = true;
</span><span class="cx">     for (const CSSSelector* selector = &amp;firstSelector; selector; selector = selector-&gt;tagHistory()) {
</span><del>-        if (selector-&gt;match() == CSSSelector::Id) {
</del><ins>+        if (canBeUsedForIdFastPath(*selector)) {
</ins><span class="cx">             if (inRightmost)
</span><span class="cx">                 return IdMatchingType::Rightmost;
</span><span class="cx">             return IdMatchingType::Filter;
</span><span class="lines">@@ -88,11 +95,11 @@
</span><span class="cx">             case CSSSelector::Class:
</span><span class="cx">                 m_matchType = ClassNameMatch;
</span><span class="cx">                 break;
</span><del>-            case CSSSelector::Id:
-                m_matchType = RightMostWithIdMatch;
-                break;
</del><span class="cx">             default:
</span><del>-                m_matchType = CompilableSingle;
</del><ins>+                if (canBeUsedForIdFastPath(selector))
+                    m_matchType = RightMostWithIdMatch;
+                else
+                    m_matchType = CompilableSingle;
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">         } else {
</span><span class="lines">@@ -194,7 +201,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="cx">     for (const CSSSelector* selector = &amp;firstSelector; selector; selector = selector-&gt;tagHistory()) {
</span><del>-        if (selector-&gt;match() == CSSSelector::Id)
</del><ins>+        if (canBeUsedForIdFastPath(*selector))
</ins><span class="cx">             return selector;
</span><span class="cx">         if (selector-&gt;relation() != CSSSelector::SubSelector)
</span><span class="cx">             break;
</span><span class="lines">@@ -247,7 +254,7 @@
</span><span class="cx">     // Thus we can skip the rightmost match.
</span><span class="cx">     const CSSSelector* selector = &amp;firstSelector;
</span><span class="cx">     do {
</span><del>-        ASSERT(selector-&gt;match() != CSSSelector::Id);
</del><ins>+        ASSERT(!canBeUsedForIdFastPath(*selector));
</ins><span class="cx">         if (selector-&gt;relation() != CSSSelector::SubSelector)
</span><span class="cx">             break;
</span><span class="cx">         selector = selector-&gt;tagHistory();
</span><span class="lines">@@ -255,7 +262,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool inAdjacentChain = false;
</span><span class="cx">     for (; selector; selector = selector-&gt;tagHistory()) {
</span><del>-        if (selector-&gt;match() == CSSSelector::Id) {
</del><ins>+        if (canBeUsedForIdFastPath(*selector)) {
</ins><span class="cx">             const AtomicString&amp; idToMatch = selector-&gt;value();
</span><span class="cx">             if (ContainerNode* searchRoot = rootNode.treeScope().getElementById(idToMatch)) {
</span><span class="cx">                 if (LIKELY(!rootNode.treeScope().containsMultipleElementsWithId(idToMatch))) {
</span></span></pre>
</div>
</div>

</body>
</html>