Chromium Code Reviews| 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())) { |