
With this change, we now have ~1200 CellAllocators across both LibJS and LibWeb in a normal WebContent instance. This gives us a minimum heap size of 4.7 MiB in the scenario where we only have one cell allocated per type. Of course, in practice there will be many more of each type, so the effective overhead is quite a bit smaller than that in practice. I left a few types unconverted to this mechanism because I got tired of doing this. :^)
65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2022-2023, networkException <networkexception@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/HTML/Scripting/ModuleMap.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
JS_DEFINE_ALLOCATOR(ModuleMap);
|
|
|
|
void ModuleMap::visit_edges(Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
for (auto& it : m_values)
|
|
visitor.visit(it.value.module_script);
|
|
|
|
for (auto const& it : m_callbacks)
|
|
for (auto const& callback : it.value)
|
|
visitor.visit(callback);
|
|
}
|
|
|
|
bool ModuleMap::is_fetching(AK::URL const& url, DeprecatedString const& type) const
|
|
{
|
|
return is(url, type, EntryType::Fetching);
|
|
}
|
|
|
|
bool ModuleMap::is_failed(AK::URL const& url, DeprecatedString const& type) const
|
|
{
|
|
return is(url, type, EntryType::Failed);
|
|
}
|
|
|
|
bool ModuleMap::is(AK::URL const& url, DeprecatedString const& type, EntryType entry_type) const
|
|
{
|
|
auto value = m_values.get({ url, type });
|
|
if (!value.has_value())
|
|
return false;
|
|
|
|
return value->type == entry_type;
|
|
}
|
|
|
|
Optional<ModuleMap::Entry> ModuleMap::get(AK::URL const& url, DeprecatedString const& type) const
|
|
{
|
|
return m_values.get({ url, type });
|
|
}
|
|
|
|
AK::HashSetResult ModuleMap::set(AK::URL const& url, DeprecatedString const& type, Entry entry)
|
|
{
|
|
auto value = m_values.set({ url, type }, entry);
|
|
|
|
auto callbacks = m_callbacks.get({ url, type });
|
|
if (callbacks.has_value())
|
|
for (auto const& callback : *callbacks)
|
|
callback->function()(entry);
|
|
|
|
return value;
|
|
}
|
|
|
|
void ModuleMap::wait_for_change(JS::Heap& heap, AK::URL const& url, DeprecatedString const& type, Function<void(Entry)> callback)
|
|
{
|
|
m_callbacks.ensure({ url, type }).append(JS::create_heap_function(heap, move(callback)));
|
|
}
|
|
|
|
}
|