mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibJS/Bytecode: Make NewPrimitiveArray a variable-length instruction
Instead of having a FixedArray with a separate heap allocation, we can just bake the primitive values into the instruction itself.
This commit is contained in:
parent
5813df21c8
commit
60a555e364
4 changed files with 44 additions and 13 deletions
|
@ -1024,14 +1024,15 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> ArrayExpression::ge
|
|||
if (all_of(m_elements, [](auto element) { return !element || is<PrimitiveLiteral>(*element); })) {
|
||||
// If all elements are constant primitives, we can just emit a single instruction to initialize the array,
|
||||
// instead of emitting instructions to manually evaluate them one-by-one
|
||||
auto values = MUST(FixedArray<Value>::create(m_elements.size()));
|
||||
Vector<Value> values;
|
||||
values.resize(m_elements.size());
|
||||
for (auto i = 0u; i < m_elements.size(); ++i) {
|
||||
if (!m_elements[i])
|
||||
continue;
|
||||
values[i] = static_cast<PrimitiveLiteral const&>(*m_elements[i]).value();
|
||||
}
|
||||
auto dst = choose_dst(generator, preferred_dst);
|
||||
generator.emit<Bytecode::Op::NewPrimitiveArray>(dst, move(values));
|
||||
generator.emit_with_extra_value_slots<Bytecode::Op::NewPrimitiveArray>(values.size(), dst, values);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue