Commit 7166178c authored by esprehn's avatar esprehn Committed by Commit bot

Remove isTreeScopeRoot and just rely on isDescendantOf instead.

Today the SelectorQuery code does:
isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)

after getting an element from the rootNode's treeScope id map as a way to
check if the element is inside the rootNode, but if isTreeScopeRoot was
true then isDescendantOf must also be true, so all this was doing was saving
a function call and a few branches for the elements with the matching id. This
doesn't seem worth the added complexity, so lets just rely on isDescendantOf.

This also lets us remove isTreeScopeRoot function, which is semantically
equivalent to Node::isTreeScope() anyway.

BUG=703900

Review-Url: https://codereview.chromium.org/2768263006
Cr-Commit-Position: refs/heads/master@{#459734}
parent b2cdcbfc
......@@ -965,14 +965,6 @@ inline bool Node::shouldCallRecalcStyle(StyleRecalcChange change) {
childNeedsStyleRecalc();
}
inline bool isTreeScopeRoot(const Node* node) {
return !node || node->isDocumentNode() || node->isShadowRoot();
}
inline bool isTreeScopeRoot(const Node& node) {
return node.isDocumentNode() || node.isShadowRoot();
}
// See the comment at the declaration of ScriptWrappable::fromNode in
// bindings/core/v8/ScriptWrappable.h about why this method is defined here.
inline ScriptWrappable* ScriptWrappable::fromNode(Node* node) {
......
......@@ -250,8 +250,7 @@ void SelectorQuery::findTraverseRootsAndExecute(
Element* element =
rootNode.containingTreeScope().getElementById(selector->value());
ContainerNode* adjustedNode = &rootNode;
if (element &&
(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)))
if (element && element->isDescendantOf(&rootNode))
adjustedNode = element;
else if (!element || isRightmostSelector)
adjustedNode = nullptr;
......@@ -509,7 +508,7 @@ void SelectorQuery::execute(
const HeapVector<Member<Element>>& elements =
rootNode.treeScope().getAllElementsById(idToMatch);
for (const auto& element : elements) {
if (!(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)))
if (!element->isDescendantOf(&rootNode))
continue;
if (selectorMatches(selector, *element, rootNode)) {
SelectorQueryTrait::appendElement(output, *element);
......@@ -520,8 +519,9 @@ void SelectorQuery::execute(
return;
}
Element* element = rootNode.treeScope().getElementById(idToMatch);
if (!element ||
!(isTreeScopeRoot(rootNode) || element->isDescendantOf(&rootNode)))
if (!element)
return;
if (!element->isDescendantOf(&rootNode))
return;
if (selectorMatches(selector, *element, rootNode))
SelectorQueryTrait::appendElement(output, *element);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment