<!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 <bpoulain@apple.com> 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 <bpoulain@apple.com>
+
+ 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 <cdumez@apple.com>
</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 "PASS" messages, followed by "TEST COMPLETE".
+
+
+Trivial Selector used as rightmost
+PASS document.querySelectorAll("[id=simple_unique]").length is 1
+PASS document.querySelectorAll("[id=simple_Duplicated]").length is 3
+PASS document.querySelectorAll("[id=simple_duplicated]").length is 0
+Non-Trivial Selector used as rightmost
+PASS document.querySelectorAll("div[id=simple_unique][data-case]").length is 1
+PASS document.querySelectorAll("div[id=simple_Duplicated][data-case]").length is 3
+PASS document.querySelectorAll("div[id=simple_duplicated][data-case]").length is 0
+Trivial Selector used as ancestor filter
+PASS document.querySelectorAll("[id=Ancestor_Unique] >> *").length is 4
+PASS document.querySelectorAll("[id=Ancestor_Unique] > * >> *").length is 2
+PASS document.querySelectorAll("[id=Ancestor_Unique] >> * > *").length is 2
+PASS document.querySelectorAll("[id=ancestor_unique] >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_unique] > * >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_unique] >> * > *").length is 0
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] >> *").length is 5
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] > * >> *").length is 2
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] >> * > *").length is 2
+PASS document.querySelectorAll("[id=ancestor_duplicated] >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_duplicated] > * >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_duplicated] >> * > *").length is 0
+Non-Trivial Selector used as ancestor filter
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] >> *").length is 4
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] > * >> *").length is 2
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] >> * > *").length is 2
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] > * >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] >> * > *").length is 0
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] >> *").length is 5
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] > * >> *").length is 2
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] >> * > *").length is 2
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] > * >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] >> * > *").length is 0
+Trivial Selector used as sibling filter
+PASS document.querySelectorAll("[id=simple_unique] + *").length is 1
+PASS document.querySelectorAll("[id=simple_unique] ~ *").length is 5
+PASS document.querySelectorAll("[id=simple_Duplicated] + *").length is 3
+PASS document.querySelectorAll("[id=simple_Duplicated] ~ *").length is 4
+PASS document.querySelectorAll("[id=simple_duplicated] + *").length is 0
+PASS document.querySelectorAll("[id=simple_duplicated] ~ *").length is 0
+Trivial Selector used as sibling of ancestor filter
+PASS document.querySelectorAll("[id=simple_unique] + * > *").length is 0
+PASS document.querySelectorAll("[id=simple_unique] ~ * > *").length is 4
+PASS document.querySelectorAll("[id=simple_Duplicated] + * > *").length is 2
+PASS document.querySelectorAll("[id=simple_Duplicated] ~ * > *").length is 4
+PASS document.querySelectorAll("[id=simple_duplicated] + * > *").length is 0
+PASS document.querySelectorAll("[id=simple_duplicated] ~ * > *").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 "PASS" messages, followed by "TEST COMPLETE".
+
+
+Trivial Selector used as rightmost
+PASS document.querySelectorAll("[id=simple_unique]").length is 1
+PASS document.querySelectorAll("[id=simple_Duplicated]").length is 3
+PASS document.querySelectorAll("[id=simple_duplicated]").length is 0
+Non-Trivial Selector used as rightmost
+PASS document.querySelectorAll("div[id=simple_unique][data-case]").length is 1
+PASS document.querySelectorAll("div[id=simple_Duplicated][data-case]").length is 3
+PASS document.querySelectorAll("div[id=simple_duplicated][data-case]").length is 0
+Trivial Selector used as ancestor filter
+PASS document.querySelectorAll("[id=Ancestor_Unique] >> *").length is 4
+PASS document.querySelectorAll("[id=Ancestor_Unique] > * >> *").length is 2
+PASS document.querySelectorAll("[id=Ancestor_Unique] >> * > *").length is 2
+PASS document.querySelectorAll("[id=ancestor_unique] >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_unique] > * >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_unique] >> * > *").length is 0
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] >> *").length is 5
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] > * >> *").length is 2
+PASS document.querySelectorAll("[id=ANCESTOR_DUPLICATED] >> * > *").length is 2
+PASS document.querySelectorAll("[id=ancestor_duplicated] >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_duplicated] > * >> *").length is 0
+PASS document.querySelectorAll("[id=ancestor_duplicated] >> * > *").length is 0
+Non-Trivial Selector used as ancestor filter
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] >> *").length is 4
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] > * >> *").length is 2
+PASS document.querySelectorAll("div[id=Ancestor_Unique][data-case] >> * > *").length is 2
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] > * >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_unique][data-case] >> * > *").length is 0
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] >> *").length is 5
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] > * >> *").length is 2
+PASS document.querySelectorAll("div[id=ANCESTOR_DUPLICATED][data-case] >> * > *").length is 2
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] > * >> *").length is 0
+PASS document.querySelectorAll("div[id=ancestor_duplicated][data-case] >> * > *").length is 0
+Trivial Selector used as sibling filter
+PASS document.querySelectorAll("[id=simple_unique] + *").length is 1
+PASS document.querySelectorAll("[id=simple_unique] ~ *").length is 5
+PASS document.querySelectorAll("[id=simple_Duplicated] + *").length is 3
+PASS document.querySelectorAll("[id=simple_Duplicated] ~ *").length is 4
+PASS document.querySelectorAll("[id=simple_duplicated] + *").length is 0
+PASS document.querySelectorAll("[id=simple_duplicated] ~ *").length is 0
+Trivial Selector used as sibling of ancestor filter
+PASS document.querySelectorAll("[id=simple_unique] + * > *").length is 0
+PASS document.querySelectorAll("[id=simple_unique] ~ * > *").length is 4
+PASS document.querySelectorAll("[id=simple_Duplicated] + * > *").length is 2
+PASS document.querySelectorAll("[id=simple_Duplicated] ~ * > *").length is 4
+PASS document.querySelectorAll("[id=simple_duplicated] + * > *").length is 0
+PASS document.querySelectorAll("[id=simple_duplicated] ~ * > *").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>+<html>
+ <head>
+ <script src="../../resources/js-test-pre.js"></script>
+ </head>
+ <body>
+ <div class="display:none;">
+ <div id="simple_unique" data-case="1"></div>
+ <div id="simple_Duplicated" data-case="2"></div>
+ <div id="simple_Duplicated" data-case="3"></div>
+ <div id="simple_Duplicated" data-case="4"></div>
+
+ <div id="Ancestor_Unique" data-case="5">
+ <div data-case="6">
+ <div data-case="7">
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="8">
+ <div data-case="9">
+ </div>
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="10">
+ <div data-case="11">
+ <div data-case="12">
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="13">
+ <div data-case="14">
+ </div>
+ </div>
+ </div>
+ </div>
+ <script>
+ description("Verify the optimization transforming [id=value] into #value for querySelector.");
+
+ function test(selector, expectedCases)
+ {
+ shouldBe('document.querySelectorAll("' + selector + '").length', '' + expectedCases.length);
+ /*let queryResult = document.querySelectorAll(selector);
+ for (let i = 0; i < queryResult.length; ++i) {
+ shouldBeEqualToString('document.querySelectorAll("' + selector + '")[' + i + '].dataset.case', '' + expectedCases[i]);
+ }*/
+ }
+
+ debug("Trivial Selector used as rightmost");
+ test("[id=simple_unique]", [1]);
+ test("[id=simple_Duplicated]", [2, 3, 4]);
+ test("[id=simple_duplicated]", []);
+
+ debug("Non-Trivial Selector used as rightmost");
+ test("div[id=simple_unique][data-case]", [1]);
+ test("div[id=simple_Duplicated][data-case]", [2, 3, 4]);
+ test("div[id=simple_duplicated][data-case]", []);
+
+ debug("Trivial Selector used as ancestor filter");
+ test("[id=Ancestor_Unique] >> *", [6, 7, 8, 9]);
+ test("[id=Ancestor_Unique] > * >> *", [7, 9]);
+ test("[id=Ancestor_Unique] >> * > *", [7, 9]);
+ test("[id=ancestor_unique] >> *", []);
+ test("[id=ancestor_unique] > * >> *", []);
+ test("[id=ancestor_unique] >> * > *", []);
+ test("[id=ANCESTOR_DUPLICATED] >> *", [9, 11, 12, 13, 14]);
+ test("[id=ANCESTOR_DUPLICATED] > * >> *", [12, 14]);
+ test("[id=ANCESTOR_DUPLICATED] >> * > *", [12, 14]);
+ test("[id=ancestor_duplicated] >> *", []);
+ test("[id=ancestor_duplicated] > * >> *", []);
+ test("[id=ancestor_duplicated] >> * > *", []);
+
+ debug("Non-Trivial Selector used as ancestor filter");
+ test("div[id=Ancestor_Unique][data-case] >> *", [6, 7, 8, 9]);
+ test("div[id=Ancestor_Unique][data-case] > * >> *", [7, 9]);
+ test("div[id=Ancestor_Unique][data-case] >> * > *", [7, 9]);
+ test("div[id=ancestor_unique][data-case] >> *", []);
+ test("div[id=ancestor_unique][data-case] > * >> *", []);
+ test("div[id=ancestor_unique][data-case] >> * > *", []);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] >> *", [9, 11, 12, 13, 14]);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] > * >> *", [12, 14]);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] >> * > *", [12, 14]);
+ test("div[id=ancestor_duplicated][data-case] >> *", []);
+ test("div[id=ancestor_duplicated][data-case] > * >> *", []);
+ test("div[id=ancestor_duplicated][data-case] >> * > *", []);
+
+ debug("Trivial Selector used as sibling filter");
+ test("[id=simple_unique] + *", [2]);
+ test("[id=simple_unique] ~ *", [2, 3, 4, 5, 10]);
+ test("[id=simple_Duplicated] + *", [3, 4, 5]);
+ test("[id=simple_Duplicated] ~ *", [3, 4, 5, 10]);
+ test("[id=simple_duplicated] + *", []);
+ test("[id=simple_duplicated] ~ *", []);
+
+ debug("Trivial Selector used as sibling of ancestor filter");
+ test("[id=simple_unique] + * > *", []);
+ test("[id=simple_unique] ~ * > *", [6, 8, 11, 13]);
+ test("[id=simple_Duplicated] + * > *", [6, 8]);
+ test("[id=simple_Duplicated] ~ * > *", [6, 8, 11, 13]);
+ test("[id=simple_duplicated] + * > *", []);
+ test("[id=simple_duplicated] ~ * > *", []);
+ </script>
+ <script src="../../resources/js-test-post.js"></script>
+ </body>
+</html>
</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>+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="../../resources/js-test-pre.js"></script>
+ </head>
+ <body>
+ <div class="display:none;">
+ <div id="simple_unique" data-case="1"></div>
+ <div id="simple_Duplicated" data-case="2"></div>
+ <div id="simple_Duplicated" data-case="3"></div>
+ <div id="simple_Duplicated" data-case="4"></div>
+
+ <div id="Ancestor_Unique" data-case="5">
+ <div data-case="6">
+ <div data-case="7">
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="8">
+ <div data-case="9">
+ </div>
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="10">
+ <div data-case="11">
+ <div data-case="12">
+ </div>
+ </div>
+ <div id="ANCESTOR_DUPLICATED" data-case="13">
+ <div data-case="14">
+ </div>
+ </div>
+ </div>
+ </div>
+ <script>
+ description("Verify the optimization transforming [id=value] into #value for querySelector.");
+
+ function test(selector, expectedCases)
+ {
+ shouldBe('document.querySelectorAll("' + selector + '").length', '' + expectedCases.length);
+ /*let queryResult = document.querySelectorAll(selector);
+ for (let i = 0; i < queryResult.length; ++i) {
+ shouldBeEqualToString('document.querySelectorAll("' + selector + '")[' + i + '].dataset.case', '' + expectedCases[i]);
+ }*/
+ }
+
+ debug("Trivial Selector used as rightmost");
+ test("[id=simple_unique]", [1]);
+ test("[id=simple_Duplicated]", [2, 3, 4]);
+ test("[id=simple_duplicated]", []);
+
+ debug("Non-Trivial Selector used as rightmost");
+ test("div[id=simple_unique][data-case]", [1]);
+ test("div[id=simple_Duplicated][data-case]", [2, 3, 4]);
+ test("div[id=simple_duplicated][data-case]", []);
+
+ debug("Trivial Selector used as ancestor filter");
+ test("[id=Ancestor_Unique] >> *", [6, 7, 8, 9]);
+ test("[id=Ancestor_Unique] > * >> *", [7, 9]);
+ test("[id=Ancestor_Unique] >> * > *", [7, 9]);
+ test("[id=ancestor_unique] >> *", []);
+ test("[id=ancestor_unique] > * >> *", []);
+ test("[id=ancestor_unique] >> * > *", []);
+ test("[id=ANCESTOR_DUPLICATED] >> *", [9, 11, 12, 13, 14]);
+ test("[id=ANCESTOR_DUPLICATED] > * >> *", [12, 14]);
+ test("[id=ANCESTOR_DUPLICATED] >> * > *", [12, 14]);
+ test("[id=ancestor_duplicated] >> *", []);
+ test("[id=ancestor_duplicated] > * >> *", []);
+ test("[id=ancestor_duplicated] >> * > *", []);
+
+ debug("Non-Trivial Selector used as ancestor filter");
+ test("div[id=Ancestor_Unique][data-case] >> *", [6, 7, 8, 9]);
+ test("div[id=Ancestor_Unique][data-case] > * >> *", [7, 9]);
+ test("div[id=Ancestor_Unique][data-case] >> * > *", [7, 9]);
+ test("div[id=ancestor_unique][data-case] >> *", []);
+ test("div[id=ancestor_unique][data-case] > * >> *", []);
+ test("div[id=ancestor_unique][data-case] >> * > *", []);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] >> *", [9, 11, 12, 13, 14]);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] > * >> *", [12, 14]);
+ test("div[id=ANCESTOR_DUPLICATED][data-case] >> * > *", [12, 14]);
+ test("div[id=ancestor_duplicated][data-case] >> *", []);
+ test("div[id=ancestor_duplicated][data-case] > * >> *", []);
+ test("div[id=ancestor_duplicated][data-case] >> * > *", []);
+
+ debug("Trivial Selector used as sibling filter");
+ test("[id=simple_unique] + *", [2]);
+ test("[id=simple_unique] ~ *", [2, 3, 4, 5, 10]);
+ test("[id=simple_Duplicated] + *", [3, 4, 5]);
+ test("[id=simple_Duplicated] ~ *", [3, 4, 5, 10]);
+ test("[id=simple_duplicated] + *", []);
+ test("[id=simple_duplicated] ~ *", []);
+
+ debug("Trivial Selector used as sibling of ancestor filter");
+ test("[id=simple_unique] + * > *", []);
+ test("[id=simple_unique] ~ * > *", [6, 8, 11, 13]);
+ test("[id=simple_Duplicated] + * > *", [6, 8]);
+ test("[id=simple_Duplicated] ~ * > *", [6, 8, 11, 13]);
+ test("[id=simple_duplicated] + * > *", []);
+ test("[id=simple_duplicated] ~ * > *", []);
+ </script>
+ <script src="../../resources/js-test-post.js"></script>
+ </body>
+</html>
</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 <bpoulain@apple.com>
+
+ 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 <cdumez@apple.com>
</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 <utatane.tea@gmail.com>
</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 "CSSParser.h"
</span><span class="cx"> #include "ElementDescendantIterator.h"
</span><ins>+#include "HTMLNames.h"
</ins><span class="cx"> #include "SelectorChecker.h"
</span><span class="cx"> #include "StaticNodeList.h"
</span><span class="cx"> #include "StyledElement.h"
</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& selector)
+{
+ return selector.match() == CSSSelector::Id
+ || (selector.match() == CSSSelector::Exact && selector.attribute() == HTMLNames::idAttr && !selector.attributeValueMatchingIsCaseInsensitive());
+}
+
</ins><span class="cx"> static IdMatchingType findIdMatchingType(const CSSSelector& firstSelector)
</span><span class="cx"> {
</span><span class="cx"> bool inRightmost = true;
</span><span class="cx"> for (const CSSSelector* selector = &firstSelector; selector; selector = selector->tagHistory()) {
</span><del>- if (selector->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 = &firstSelector; selector; selector = selector->tagHistory()) {
</span><del>- if (selector->match() == CSSSelector::Id)
</del><ins>+ if (canBeUsedForIdFastPath(*selector))
</ins><span class="cx"> return selector;
</span><span class="cx"> if (selector->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 = &firstSelector;
</span><span class="cx"> do {
</span><del>- ASSERT(selector->match() != CSSSelector::Id);
</del><ins>+ ASSERT(!canBeUsedForIdFastPath(*selector));
</ins><span class="cx"> if (selector->relation() != CSSSelector::SubSelector)
</span><span class="cx"> break;
</span><span class="cx"> selector = selector->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->tagHistory()) {
</span><del>- if (selector->match() == CSSSelector::Id) {
</del><ins>+ if (canBeUsedForIdFastPath(*selector)) {
</ins><span class="cx"> const AtomicString& idToMatch = selector->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>