1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibWeb: Only allocate DOM::Node registered observer list on demand

Most DOM nodes don't have registered mutation observers, so let's put
the metadata about them behind an OwnPtr to save space in the common
case.

Saves 16 bytes per DOM node that doesn't have registered observers.
This commit is contained in:
Andreas Kling 2023-11-18 11:22:51 +01:00
parent c1fd55ce94
commit 9edfd5e360
4 changed files with 53 additions and 32 deletions

View file

@ -608,9 +608,11 @@ void queue_mutation_observer_microtask(DOM::Document const& document)
if (node.is_null())
continue;
node->registered_observers_list().remove_all_matching([&mutation_observer](DOM::RegisteredObserver& registered_observer) {
return is<DOM::TransientRegisteredObserver>(registered_observer) && static_cast<DOM::TransientRegisteredObserver&>(registered_observer).observer().ptr() == mutation_observer.ptr();
});
if (node->registered_observer_list()) {
node->registered_observer_list()->remove_all_matching([&mutation_observer](DOM::RegisteredObserver& registered_observer) {
return is<DOM::TransientRegisteredObserver>(registered_observer) && static_cast<DOM::TransientRegisteredObserver&>(registered_observer).observer().ptr() == mutation_observer.ptr();
});
}
}
// 4. If records is not empty, then invoke mos callback with « records, mo », and mo. If this throws an exception, catch it, and report the exception.