LibJS: Use a local variable for arguments object when possible

This allows us to skip allocating a function environment in cases where
it was previously impossible because the arguments object needed a
binding.

This change does not bring visible improvement in Kraken or Octane
benchmarks but seems useful to have anyway.
This commit is contained in:
Aliaksandr Kalenik 2024-05-21 09:32:51 +01:00 committed by Andreas Kling
parent 777e84b09b
commit 210a5d77dc
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
5 changed files with 39 additions and 11 deletions

View file

@ -45,10 +45,15 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
}
if (function.m_arguments_object_needed) {
Optional<Operand> dst;
auto local_var_index = function.m_local_variables_names.find_first_index("arguments"sv);
if (local_var_index.has_value())
dst = local(local_var_index.value());
if (function.m_strict || !function.has_simple_parameter_list()) {
emit<Op::CreateArguments>(Op::CreateArguments::Kind::Unmapped, function.m_strict);
emit<Op::CreateArguments>(dst, Op::CreateArguments::Kind::Unmapped, function.m_strict);
} else {
emit<Op::CreateArguments>(Op::CreateArguments::Kind::Mapped, function.m_strict);
emit<Op::CreateArguments>(dst, Op::CreateArguments::Kind::Mapped, function.m_strict);
}
}