Skip to content

Commit

Permalink
Reduce branching a little under JSNodeOwner::isReachableFromOpaqueRoo…
Browse files Browse the repository at this point in the history
…ts()

https://bugs.webkit.org/show_bug.cgi?id=240742

Reviewed by Geoffrey Garen.

Given that JSNodeOwner::isReachableFromOpaqueRoots() already checks if the Node is
connected or not, make sure to avoid the same check under Node::opaqueRoot().

* Source/WebCore/bindings/js/JSNodeCustom.cpp:
(WebCore::JSNodeOwner::isReachableFromOpaqueRoots):
* Source/WebCore/dom/Node.cpp:
(WebCore::Node::traverseToOpaqueRoot const):
(WebCore::Node::opaqueRootSlow const): Deleted.
* Source/WebCore/dom/Node.h:
(WebCore::Node::opaqueRoot const):

Canonical link: https://commits.webkit.org/250831@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294605 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 21, 2022
1 parent 07e3f90 commit 7950c18
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Source/WebCore/bindings/js/JSNodeCustom.cpp
Expand Up @@ -74,12 +74,13 @@ bool JSNodeOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, v
*reason = "Node is scheduled to be used in an async script invocation)";
return true;
}
return visitor.containsOpaqueRoot(node.traverseToOpaqueRoot());
}

if (UNLIKELY(reason))
*reason = "Connected node";

return visitor.containsOpaqueRoot(root(node));
return visitor.containsOpaqueRoot(&node.document());
}

JSScope* JSNode::pushEventHandlerScope(JSGlobalObject* lexicalGlobalObject, JSScope* node) const
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/dom/Node.cpp
Expand Up @@ -2639,8 +2639,9 @@ bool Node::inRenderedDocument() const
return isConnected() && document().hasLivingRenderTree();
}

void* Node::opaqueRootSlow() const
void* Node::traverseToOpaqueRoot() const
{
ASSERT_WITH_MESSAGE(!isConnected(), "Call opaqueRoot() or document() when the node is connected");
const Node* node = this;
for (;;) {
const Node* nextNode = node->parentOrShadowHostNode();
Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/dom/Node.h
Expand Up @@ -267,6 +267,7 @@ class Node : public EventTarget {
Node& getRootNode(const GetRootNodeOptions&) const;

void* opaqueRoot() const;
void* traverseToOpaqueRoot() const;

void queueTaskKeepingThisNodeAlive(TaskSource, Function<void ()>&&);
void queueTaskToDispatchEvent(TaskSource, Ref<Event>&&);
Expand Down Expand Up @@ -716,8 +717,6 @@ class Node : public EventTarget {

void adjustStyleValidity(Style::Validity, Style::InvalidationMode);

void* opaqueRootSlow() const;

static void moveShadowTreeToNewDocument(ShadowRoot&, Document& oldDocument, Document& newDocument);
static void moveTreeToNewScope(Node&, TreeScope& oldScope, TreeScope& newScope);
void moveNodeToNewDocument(Document& oldDocument, Document& newDocument);
Expand Down Expand Up @@ -852,7 +851,7 @@ inline void* Node::opaqueRoot() const
// https://bugs.webkit.org/show_bug.cgi?id=165713
if (isConnected())
return &document();
return opaqueRootSlow();
return traverseToOpaqueRoot();
}

inline ContainerNode* Node::parentNodeGuaranteedHostFree() const
Expand Down

0 comments on commit 7950c18

Please sign in to comment.