1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibJS: Instantiate primitive array expressions using a single operation

This will not meaningfully affect short array literals, but it does
give us a bit of extra perf when evaluating huge array expressions like
in Kraken/imaging-darkroom.js
This commit is contained in:
Idan Horowitz 2023-11-17 22:07:23 +02:00 committed by Andreas Kling
parent 5e3a799e97
commit f19349e1b6
7 changed files with 92 additions and 6 deletions

View file

@ -605,6 +605,15 @@ ThrowCompletionOr<void> NewArray::execute_impl(Bytecode::Interpreter& interprete
return {};
}
ThrowCompletionOr<void> NewPrimitiveArray::execute_impl(Bytecode::Interpreter& interpreter) const
{
auto array = MUST(Array::create(interpreter.realm(), 0));
for (size_t i = 0; i < m_values.size(); i++)
array->indexed_properties().put(i, m_values[i], default_attributes);
interpreter.accumulator() = array;
return {};
}
ThrowCompletionOr<void> Append::execute_impl(Bytecode::Interpreter& interpreter) const
{
return append(interpreter.vm(), interpreter.reg(m_lhs), interpreter.accumulator(), m_is_spread);
@ -1306,6 +1315,11 @@ DeprecatedString NewArray::to_deprecated_string_impl(Bytecode::Executable const&
return builder.to_deprecated_string();
}
DeprecatedString NewPrimitiveArray::to_deprecated_string_impl(Bytecode::Executable const&) const
{
return DeprecatedString::formatted("NewPrimitiveArray {}"sv, m_values.span());
}
DeprecatedString Append::to_deprecated_string_impl(Bytecode::Executable const&) const
{
if (m_is_spread)