mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +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
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 (auto* exception = interpreter.exception()) {
|
||||||
if (m_handler) {
|
if (m_handler) {
|
||||||
interpreter.clear_exception();
|
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));
|
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())
|
if (!statement.is_scope_node())
|
||||||
return statement.execute(*this);
|
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();
|
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;
|
HashMap<FlyString, Variable> scope_variables_with_declaration_type;
|
||||||
for (auto& argument : arguments) {
|
for (auto& argument : arguments) {
|
||||||
|
|
|
@ -67,6 +67,8 @@ struct Argument {
|
||||||
Value value;
|
Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef Vector<Argument, 8> ArgumentVector;
|
||||||
|
|
||||||
class Interpreter {
|
class Interpreter {
|
||||||
public:
|
public:
|
||||||
template<typename GlobalObjectType, typename... Args>
|
template<typename GlobalObjectType, typename... Args>
|
||||||
|
@ -79,7 +81,7 @@ public:
|
||||||
|
|
||||||
~Interpreter();
|
~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; }
|
Object& global_object() { return *m_global_object; }
|
||||||
const Object& global_object() const { 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 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&);
|
void exit_scope(const ScopeNode&);
|
||||||
|
|
||||||
Value call(Function*, Value this_value = {}, const Vector<Value>& arguments = {});
|
Value call(Function*, Value this_value = {}, const Vector<Value>& arguments = {});
|
||||||
|
|
|
@ -48,7 +48,7 @@ ScriptFunction::~ScriptFunction()
|
||||||
Value ScriptFunction::call(Interpreter& interpreter)
|
Value ScriptFunction::call(Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
auto& argument_values = interpreter.call_frame().arguments;
|
auto& argument_values = interpreter.call_frame().arguments;
|
||||||
Vector<Argument> arguments;
|
ArgumentVector arguments;
|
||||||
for (size_t i = 0; i < m_parameters.size(); ++i) {
|
for (size_t i = 0; i < m_parameters.size(); ++i) {
|
||||||
auto name = parameters()[i];
|
auto name = parameters()[i];
|
||||||
auto value = js_undefined();
|
auto value = js_undefined();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue