From d294a3f54a848f3165a71f134b3f09d556e34a11 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 28 Sep 2021 21:58:05 +0200 Subject: [PATCH] LibJS: Avoid unnecessary HashMap growth in Interpreter::enter_scope() Don't bother pre-allocating a hash map if we're not gonna put anything into it anyway. --- Userland/Libraries/LibJS/Interpreter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp index 04d5d64f01..f69eb15f58 100644 --- a/Userland/Libraries/LibJS/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Interpreter.cpp @@ -113,7 +113,9 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type, } HashMap scope_variables_with_declaration_kind; - scope_variables_with_declaration_kind.ensure_capacity(16); + + if (!scope_node.variables().is_empty()) + scope_variables_with_declaration_kind.ensure_capacity(16); bool is_program_node = is(scope_node);