mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 00:42:54 +00:00
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:
parent
a4f70986a0
commit
3d4b13a01c
Notes:
sideshowbarker
2024-07-17 03:03:37 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 3d4b13a01c
Pull-request: https://github.com/SerenityOS/serenity/pull/24272
3 changed files with 16 additions and 5 deletions
|
@ -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 {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue