LibWeb: Allocate dataset lazily for HTML/SVG/MathML elements

Most elements never need a dataset object, so we can avoid creating lots
of objects by making them lazy.
This commit is contained in:
Andreas Kling 2024-04-24 14:56:26 +02:00
commit 4c921e17b7
Notes: sideshowbarker 2024-07-17 06:51:10 +09:00
6 changed files with 23 additions and 11 deletions

View file

@ -50,8 +50,6 @@ void HTMLElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLElement);
m_dataset = DOMStringMap::create(*this);
}
void HTMLElement::visit_edges(Cell::Visitor& visitor)
@ -60,6 +58,13 @@ void HTMLElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_dataset);
}
JS::NonnullGCPtr<DOMStringMap> HTMLElement::dataset()
{
if (!m_dataset)
m_dataset = DOMStringMap::create(*this);
return *m_dataset;
}
// https://html.spec.whatwg.org/multipage/dom.html#dom-dir
StringView HTMLElement::dir() const
{

View file

@ -53,8 +53,7 @@ public:
bool cannot_navigate() const;
DOMStringMap* dataset() { return m_dataset.ptr(); }
DOMStringMap const* dataset() const { return m_dataset.ptr(); }
[[nodiscard]] JS::NonnullGCPtr<DOMStringMap> dataset();
void focus();