Skip to content
Permalink
Browse files
Reduce branching a little under JSNodeOwner::isReachableFromOpaqueRoo…
…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 7950c18a8a1704e5d2c97ac71457b4cce162d4a8
Showing 3 changed files with 6 additions and 5 deletions.
@@ -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
@@ -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();
@@ -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>&&);
@@ -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);
@@ -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

0 comments on commit 7950c18

Please sign in to comment.