LibJS: Ensure capacity for created lexical and variable environments

If the minimal amount of required bindings is known in advance, it could
be used to ensure capacity to avoid resizing the internal vector that
holds bindings.
This commit is contained in:
Aliaksandr Kalenik 2024-05-09 17:10:20 +02:00 committed by Andreas Kling
parent a4f70986a0
commit 3d4b13a01c
Notes: sideshowbarker 2024-07-17 03:03:37 +09:00
3 changed files with 16 additions and 5 deletions

View file

@ -1256,7 +1256,9 @@ ThrowCompletionOr<void> DeleteVariable::execute_impl(Bytecode::Interpreter& inte
void CreateLexicalEnvironment::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto make_and_swap_envs = [&](auto& old_environment) {
GCPtr<Environment> environment = new_declarative_environment(*old_environment).ptr();
auto declarative_environment = new_declarative_environment(*old_environment).ptr();
declarative_environment->ensure_capacity(m_capacity);
GCPtr<Environment> environment = declarative_environment;
swap(old_environment, environment);
return environment;
};
@ -1268,6 +1270,7 @@ ThrowCompletionOr<void> CreateVariableEnvironment::execute_impl(Bytecode::Interp
{
auto& running_execution_context = interpreter.vm().running_execution_context();
auto var_environment = new_declarative_environment(*running_execution_context.lexical_environment);
var_environment->ensure_capacity(m_capacity);
running_execution_context.variable_environment = var_environment;
running_execution_context.lexical_environment = var_environment;
return {};