mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 00:21:52 +00:00
Before: `is<HTMLOLListElement>` and other similar calls in this commit are resolved to `dynamic_cast`, which incurs runtime overhead for resolving the type. The Performance hit becomes apparent when rendering large lists. Callgrind analysis points to a significant performance hit from calls to `is<...>` in `Element::list_owner`. Reference: Michael Gibbs and Bjarne Stroustrup (2006) Fast dynamic casting. Softw. Pract. Exper. 2006; 36:139–156 After: Implement inline `fast_is` virtual method that immediately resolves the type. Results in noticeable performance improvement 2x-ish for lists with 20K entries. Bonus: Convert starting value for LI elements to signed integer The spec requires the start attribute and starting value to be "integer". Firefox and Chrome support a negative start attribute. FIXME: At the time of this PR, about 134 other objects resolve `is<...>` to `dynamic_cast`. It may be a good idea to coordinate similar changes to at least [some of] the ones that my have impact on performance (maybe open a new issue?).
39 lines
879 B
C++
39 lines
879 B
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/ARIA/Roles.h>
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class HTMLMenuElement final : public HTMLElement {
|
|
WEB_PLATFORM_OBJECT(HTMLMenuElement, HTMLElement);
|
|
GC_DECLARE_ALLOCATOR(HTMLMenuElement);
|
|
|
|
public:
|
|
virtual ~HTMLMenuElement() override;
|
|
|
|
// https://www.w3.org/TR/html-aria/#el-menu
|
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::list; }
|
|
|
|
virtual bool is_html_menu_element() const override { return true; }
|
|
|
|
private:
|
|
HTMLMenuElement(DOM::Document&, DOM::QualifiedName);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
};
|
|
|
|
}
|
|
|
|
namespace Web::DOM {
|
|
|
|
template<>
|
|
inline bool Node::fast_is<Web::HTML::HTMLMenuElement>() const { return is_html_menu_element(); }
|
|
|
|
}
|