mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 17:02:56 +00:00
LibJS: Share argument values buffer between calls
This buffer is being created and then immediately destroyed, let's reuse it to reduce memory allocations.
This commit is contained in:
parent
f16eebb95c
commit
80f0900565
Notes:
github-actions[bot]
2024-11-02 10:16:54 +00:00
Author: https://github.com/yyny
Commit: 80f0900565
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2113
2 changed files with 8 additions and 3 deletions
|
@ -2545,10 +2545,9 @@ ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) c
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Value> argument_values;
|
auto argument_values = interpreter.allocate_argument_values(m_argument_count);
|
||||||
argument_values.ensure_capacity(m_argument_count);
|
|
||||||
for (size_t i = 0; i < m_argument_count; ++i)
|
for (size_t i = 0; i < m_argument_count; ++i)
|
||||||
argument_values.unchecked_append(interpreter.get(m_arguments[i]));
|
argument_values[i] = interpreter.get(m_arguments[i]);
|
||||||
interpreter.set(dst(), TRY(perform_call(interpreter, interpreter.get(m_this_value), call_type(), callee, argument_values)));
|
interpreter.set(dst(), TRY(perform_call(interpreter, interpreter.get(m_this_value), call_type(), callee, argument_values)));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,11 @@ public:
|
||||||
Executable& current_executable() { return *m_current_executable; }
|
Executable& current_executable() { return *m_current_executable; }
|
||||||
Executable const& current_executable() const { return *m_current_executable; }
|
Executable const& current_executable() const { return *m_current_executable; }
|
||||||
Optional<size_t> program_counter() const { return m_program_counter; }
|
Optional<size_t> program_counter() const { return m_program_counter; }
|
||||||
|
Span<Value> allocate_argument_values(size_t argument_count)
|
||||||
|
{
|
||||||
|
m_argument_values_buffer.resize_and_keep_capacity(argument_count);
|
||||||
|
return m_argument_values_buffer.span();
|
||||||
|
}
|
||||||
|
|
||||||
ExecutionContext& running_execution_context() { return *m_running_execution_context; }
|
ExecutionContext& running_execution_context() { return *m_running_execution_context; }
|
||||||
|
|
||||||
|
@ -98,6 +103,7 @@ private:
|
||||||
Optional<size_t&> m_program_counter;
|
Optional<size_t&> m_program_counter;
|
||||||
Span<Value> m_arguments;
|
Span<Value> m_arguments;
|
||||||
Span<Value> m_registers_and_constants_and_locals;
|
Span<Value> m_registers_and_constants_and_locals;
|
||||||
|
Vector<Value> m_argument_values_buffer;
|
||||||
ExecutionContext* m_running_execution_context { nullptr };
|
ExecutionContext* m_running_execution_context { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue