mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibJS: Don't reserve space in function environment for parameter locals
3% speed-up on Octane/typescript.js (but basically improves performance on most JS.)
This commit is contained in:
parent
bed78eb3cc
commit
1a07205c33
Notes:
sideshowbarker
2024-07-17 06:40:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1a07205c33 Pull-request: https://github.com/SerenityOS/serenity/pull/22889 Reviewed-by: https://github.com/trflynn89
@ -118,6 +118,8 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
|
||||
// 5. Let parameterNames be the BoundNames of formals.
|
||||
// 6. If parameterNames has any duplicate entries, let hasDuplicates be true. Otherwise, let hasDuplicates be false.
|
||||
|
||||
size_t parameters_in_environment = 0;
|
||||
|
||||
// NOTE: This loop performs step 5, 6, and 8.
|
||||
for (auto const& parameter : formals) {
|
||||
if (parameter.default_value)
|
||||
@ -127,6 +129,8 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
|
||||
[&](Identifier const& identifier) {
|
||||
if (m_parameter_names.set(identifier.string(), identifier.is_local() ? ParameterIsLocal::Yes : ParameterIsLocal::No) != AK::HashSetResult::InsertedNewEntry)
|
||||
m_has_duplicates = true;
|
||||
else if (!identifier.is_local())
|
||||
++parameters_in_environment;
|
||||
},
|
||||
[&](NonnullRefPtr<BindingPattern const> const& pattern) {
|
||||
if (pattern->contains_expression())
|
||||
@ -136,6 +140,8 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
|
||||
MUST(pattern->for_each_bound_identifier([&](auto& identifier) {
|
||||
if (m_parameter_names.set(identifier.string(), identifier.is_local() ? ParameterIsLocal::Yes : ParameterIsLocal::No) != AK::HashSetResult::InsertedNewEntry)
|
||||
m_has_duplicates = true;
|
||||
else if (!identifier.is_local())
|
||||
++parameters_in_environment;
|
||||
}));
|
||||
});
|
||||
}
|
||||
@ -202,7 +208,7 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
|
||||
environment_size = ¶meter_environment_bindings_count;
|
||||
}
|
||||
|
||||
*environment_size += m_parameter_names.size();
|
||||
*environment_size += parameters_in_environment;
|
||||
|
||||
HashMap<DeprecatedFlyString, ParameterIsLocal> parameter_bindings;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user