1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-12 02:30:30 +09:00
ladybird/Libraries/LibWeb/DOM/ElementByIdMap.h
Aliaksandr Kalenik 8cae20af1b LibWeb: Maintain a mapping for fast lookup in getElementById()
With this change we maintain a data structure that maps ids to
corresponding elements. This allows us to avoid tree traversal in
getElementById() in all cases except ones when lookup happens for
unconnected elements.
2025-03-26 08:36:25 +00:00

24 lines
495 B
C++

/*
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
class ElementByIdMap {
public:
void add(FlyString const& element_id, Element&);
void remove(FlyString const& element_id, Element&);
GC::Ptr<Element> get(FlyString const& element_id) const;
private:
HashMap<FlyString, Vector<WeakPtr<Element>>> m_map;
};
}