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

Unified Diff: third_party/WebKit/Source/core/dom/SelectorQuery.cpp

Issue 2786763002: Simplify the id fast path for non-right most selectors in querySelector. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/SelectorQuery.cpp
diff --git a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
index ac733e76dd62f969c43d9ace284bfba432c4bc2a..70c69a753af9bb113508ddb7356717eab6e4bb68 100644
--- a/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
+++ b/third_party/WebKit/Source/core/dom/SelectorQuery.cpp
@@ -244,30 +244,22 @@ void SelectorQuery::findTraverseRootsAndExecute(
for (const CSSSelector* selector = m_selectors[0]; selector;
selector = selector->tagHistory()) {
- if (selector->match() == CSSSelector::Id && rootNode.isInTreeScope() &&
esprehn 2017/03/29 19:59:43 We only take the fast path if rootNode.isConnected
- !rootNode.containingTreeScope().containsMultipleElementsWithId(
- selector->value())) {
- Element* element =
- rootNode.containingTreeScope().getElementById(selector->value());
- ContainerNode* adjustedNode = &rootNode;
- if (element && element->isDescendantOf(&rootNode))
esprehn 2017/03/29 19:59:43 if element was null, then there's no element in th
- adjustedNode = element;
- else if (!element || isRightmostSelector)
- adjustedNode = nullptr;
- if (isRightmostSelector) {
esprehn 2017/03/29 19:59:43 This code was not reachable, id selectors in the r
- if (!adjustedNode)
- return;
- element = toElement(adjustedNode);
- if (selectorMatches(*m_selectors[0], *element, rootNode))
- SelectorQueryTrait::appendElement(output, *element);
+ const AtomicString& value = selector->value();
+
+ if (selector->match() == CSSSelector::Id &&
+ !rootNode.containingTreeScope().containsMultipleElementsWithId(value)) {
+ // Id selectors in the right most selector are handled by the caller,
+ // we should never hit them here.
+ DCHECK(!isRightmostSelector);
+ Element* element = rootNode.containingTreeScope().getElementById(value);
+ if (!element)
return;
- }
-
- if (startFromParent && adjustedNode)
- adjustedNode = adjustedNode->parentNode();
-
- executeForTraverseRoot<SelectorQueryTrait>(adjustedNode, rootNode,
- output);
+ ContainerNode* start = &rootNode;
+ if (element->isDescendantOf(&rootNode))
+ start = element;
+ if (startFromParent)
+ start = start->parentNode();
+ executeForTraverseRoot<SelectorQueryTrait>(start, rootNode, output);
return;
}
@@ -276,8 +268,7 @@ void SelectorQuery::findTraverseRootsAndExecute(
if (!SelectorQueryTrait::shouldOnlyMatchFirstElement && !startFromParent &&
selector->match() == CSSSelector::Class) {
if (isRightmostSelector) {
- ClassElementList<AllElements> traverseRoots(rootNode,
- selector->value());
+ ClassElementList<AllElements> traverseRoots(rootNode, value);
while (!traverseRoots.isEmpty()) {
Element& element = *traverseRoots.next();
if (selectorMatches(*m_selectors[0], element, rootNode))
@@ -287,10 +278,10 @@ void SelectorQuery::findTraverseRootsAndExecute(
}
// Since there exists some ancestor element which has the class name, we
// need to see all children of rootNode.
- if (ancestorHasClassName(rootNode, selector->value()))
+ if (ancestorHasClassName(rootNode, value))
break;
- ClassElementList<OnlyRoots> traverseRoots(rootNode, selector->value());
+ ClassElementList<OnlyRoots> traverseRoots(rootNode, value);
while (!traverseRoots.isEmpty()) {
for (Element& element :
ElementTraversal::descendantsOf(*traverseRoots.next())) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698