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

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: value() asserts for tag, can't use a local. 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..c2be5f3d3718c2c39844d9bea995edb77ee4f351 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() &&
+ if (selector->match() == CSSSelector::Id &&
!rootNode.containingTreeScope().containsMultipleElementsWithId(
selector->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(selector->value());
- ContainerNode* adjustedNode = &rootNode;
- if (element && element->isDescendantOf(&rootNode))
- adjustedNode = element;
- else if (!element || isRightmostSelector)
- adjustedNode = nullptr;
- if (isRightmostSelector) {
- if (!adjustedNode)
- return;
- element = toElement(adjustedNode);
- if (selectorMatches(*m_selectors[0], *element, rootNode))
- SelectorQueryTrait::appendElement(output, *element);
+ 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;
}
« 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