LibJS: Speed up has declaration check in ScopePusher

This change speeds up the process of checking variable declaration
within the scope by replacing the iteration through all declared
variables (without the ability to exit early from the loop) with hash
map lookups.

This change cuts google maps loading by 17s on my computer.
This commit is contained in:
Aliaksandr Kalenik 2023-07-13 01:44:48 +02:00 committed by Andreas Kling
commit 7af7e90e3f
Notes: sideshowbarker 2024-07-16 18:06:41 +09:00

View file

@ -299,25 +299,10 @@ public:
}
bool scope_has_declaration = false;
MUST(m_node->for_each_var_declared_name([&](auto const& name) {
if (m_function_parameters.has_value() && m_forbidden_lexical_names.contains(name))
return;
if (name == identifier_group_name)
scope_has_declaration = true;
}));
MUST(m_node->for_each_lexically_declared_name([&](auto const& name) {
if (name == identifier_group_name)
scope_has_declaration = true;
}));
MUST(m_node->for_each_var_function_declaration_in_reverse_order([&](auto const& declaration) {
if (declaration.name() == identifier_group_name)
scope_has_declaration = true;
}));
MUST(m_node->for_each_lexical_function_declaration_in_reverse_order([&](auto const& declaration) {
if (declaration.name() == identifier_group_name)
scope_has_declaration = true;
}));
if (is_top_level() && m_var_names.contains(identifier_group_name))
scope_has_declaration = true;
else if (m_lexical_names.contains(identifier_group_name) || m_function_names.contains(identifier_group_name))
scope_has_declaration = true;
bool hoistable_function_declaration = false;
for (auto const& function_declaration : m_functions_to_hoist) {