From 4ff4ac11b93c29e9fc0728f4cc834d9b77ff5639 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 19 Sep 2023 11:37:42 +0200 Subject: [PATCH] LibJS: Remove alreadyDeclared check in FunctionDeclarationInstantiation We don't need to check if a function parameter is already declared while creating bindings for them because we deduplicate their names by storing them in a hash table in one of the previous steps. This change makes React-Redux-TodoMVC test in Speedometer run 2% faster. --- .../LibJS/Runtime/ECMAScriptFunctionObject.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index fc863cd3f8b..82c9017cdee 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -544,20 +544,18 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia // 21. For each String paramName of parameterNames, do for (auto const& parameter_name : m_parameter_names) { // a. Let alreadyDeclared be ! env.HasBinding(paramName). - auto already_declared = MUST(environment->has_binding(parameter_name)); // b. NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have parameter default values or rest parameters. // c. If alreadyDeclared is false, then - if (!already_declared) { - // i. Perform ! env.CreateMutableBinding(paramName, false). - MUST(environment->create_mutable_binding(vm, parameter_name, false)); + // NOTE: alreadyDeclared is always false because we use hash table for parameterNames + // i. Perform ! env.CreateMutableBinding(paramName, false). + MUST(environment->create_mutable_binding(vm, parameter_name, false)); - // ii. If hasDuplicates is true, then - if (m_has_duplicates) { - // 1. Perform ! env.InitializeBinding(paramName, undefined). - MUST(environment->initialize_binding(vm, parameter_name, js_undefined(), Environment::InitializeBindingHint::Normal)); - } + // ii. If hasDuplicates is true, then + if (m_has_duplicates) { + // 1. Perform ! env.InitializeBinding(paramName, undefined). + MUST(environment->initialize_binding(vm, parameter_name, js_undefined(), Environment::InitializeBindingHint::Normal)); } }