From a8559f49651fef84b599231412735cfb4b53d3f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 Mar 2024 21:27:29 +0100 Subject: [PATCH] LibWeb: Make Element::is_document_element() slightly nicer By following the spec more closely, we can actually make this function a bit more efficient (by comparing the parent against the document instead of looking for the first element child of the document). --- Userland/Libraries/LibWeb/DOM/Element.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 26ac8b0f86e5ca3..4b04d89bcfa693d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -777,7 +777,8 @@ bool Element::is_target() const // https://dom.spec.whatwg.org/#document-element bool Element::is_document_element() const { - return document().document_element() == this; + // The document element of a document is the element whose parent is that document, if it exists; otherwise null. + return parent() == &document(); } JS::NonnullGCPtr Element::get_elements_by_class_name(StringView class_names)