mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibWeb: Use tree order in HTMLFormElement::supported_property_names()
Calling into ::compare_document_position() for each node comparison inside quick_sort() is quite expensive - it calculates more than we need and allocates. Replace it with TreeNode::is_before() which does not, and gives us the required positional info.
This commit is contained in:
committed by
Tim Ledbetter
parent
bf414f5d8f
commit
e63af74dda
Notes:
github-actions[bot]
2026-04-21 13:04:07 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/e63af74dda2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/9009 Reviewed-by: https://github.com/tcl3 ✅
@@ -1075,10 +1075,9 @@ Vector<FlyString> HTMLFormElement::supported_property_names() const
|
||||
// 5. Sort sourced names by tree order of the element entry of each tuple, sorting entries with the same element by
|
||||
// putting entries whose source is id first, then entries whose source is name, and finally entries whose source
|
||||
// is past, and sorting entries with the same element and source by their age, oldest first.
|
||||
// FIXME: Require less const casts here by changing the signature of DOM::Node::compare_document_position
|
||||
quick_sort(sourced_names, [](auto const& lhs, auto const& rhs) -> bool {
|
||||
if (lhs.element != rhs.element)
|
||||
return const_cast<DOM::Element*>(lhs.element.ptr())->compare_document_position(const_cast<DOM::Element*>(rhs.element.ptr())) & DOM::Node::DOCUMENT_POSITION_FOLLOWING;
|
||||
return lhs.element->is_before(*rhs.element);
|
||||
if (lhs.source != rhs.source)
|
||||
return lhs.source < rhs.source;
|
||||
return lhs.age < rhs.age;
|
||||
|
||||
Reference in New Issue
Block a user