mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibJS: Give argument vectors an inline capacity of 8
This avoids one malloc/free pair for every function call if there are 8 arguments or fewer.
This commit is contained in:
parent
be019f28ca
commit
5495f06af5
Notes:
sideshowbarker
2024-07-19 07:50:50 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5495f06af55
4 changed files with 8 additions and 6 deletions
|
@ -959,7 +959,7 @@ Value TryStatement::execute(Interpreter& interpreter) const
|
|||
if (auto* exception = interpreter.exception()) {
|
||||
if (m_handler) {
|
||||
interpreter.clear_exception();
|
||||
Vector<Argument> arguments { { m_handler->parameter(), exception->value() } };
|
||||
ArgumentVector arguments { { m_handler->parameter(), exception->value() } };
|
||||
interpreter.run(m_handler->body(), move(arguments));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ Interpreter::~Interpreter()
|
|||
{
|
||||
}
|
||||
|
||||
Value Interpreter::run(const Statement& statement, Vector<Argument> arguments, ScopeType scope_type)
|
||||
Value Interpreter::run(const Statement& statement, ArgumentVector arguments, ScopeType scope_type)
|
||||
{
|
||||
if (!statement.is_scope_node())
|
||||
return statement.execute(*this);
|
||||
|
@ -86,7 +86,7 @@ Value Interpreter::run(const Statement& statement, Vector<Argument> arguments, S
|
|||
return did_return ? m_last_value : js_undefined();
|
||||
}
|
||||
|
||||
void Interpreter::enter_scope(const ScopeNode& scope_node, Vector<Argument> arguments, ScopeType scope_type)
|
||||
void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector arguments, ScopeType scope_type)
|
||||
{
|
||||
HashMap<FlyString, Variable> scope_variables_with_declaration_type;
|
||||
for (auto& argument : arguments) {
|
||||
|
|
|
@ -67,6 +67,8 @@ struct Argument {
|
|||
Value value;
|
||||
};
|
||||
|
||||
typedef Vector<Argument, 8> ArgumentVector;
|
||||
|
||||
class Interpreter {
|
||||
public:
|
||||
template<typename GlobalObjectType, typename... Args>
|
||||
|
@ -79,7 +81,7 @@ public:
|
|||
|
||||
~Interpreter();
|
||||
|
||||
Value run(const Statement&, Vector<Argument> = {}, ScopeType = ScopeType::Block);
|
||||
Value run(const Statement&, ArgumentVector = {}, ScopeType = ScopeType::Block);
|
||||
|
||||
Object& global_object() { return *m_global_object; }
|
||||
const Object& global_object() const { return *m_global_object; }
|
||||
|
@ -97,7 +99,7 @@ public:
|
|||
|
||||
void gather_roots(Badge<Heap>, HashTable<Cell*>&);
|
||||
|
||||
void enter_scope(const ScopeNode&, Vector<Argument>, ScopeType);
|
||||
void enter_scope(const ScopeNode&, ArgumentVector, ScopeType);
|
||||
void exit_scope(const ScopeNode&);
|
||||
|
||||
Value call(Function*, Value this_value = {}, const Vector<Value>& arguments = {});
|
||||
|
|
|
@ -48,7 +48,7 @@ ScriptFunction::~ScriptFunction()
|
|||
Value ScriptFunction::call(Interpreter& interpreter)
|
||||
{
|
||||
auto& argument_values = interpreter.call_frame().arguments;
|
||||
Vector<Argument> arguments;
|
||||
ArgumentVector arguments;
|
||||
for (size_t i = 0; i < m_parameters.size(); ++i) {
|
||||
auto name = parameters()[i];
|
||||
auto value = js_undefined();
|
||||
|
|
Loading…
Add table
Reference in a new issue