mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:37:35 +00:00
LibJS: Remove unnecessary malloc+free in AssignmentExpression::execute
We were creating a temporary AK::Function for no good reason, and this was dominating profiles. Reorganize the code so it's not necessary.
This commit is contained in:
parent
76bb0fab2d
commit
6e7713a5f4
1 changed files with 13 additions and 18 deletions
|
@ -651,23 +651,6 @@ void Identifier::dump(int indent) const
|
||||||
|
|
||||||
Value AssignmentExpression::execute(Interpreter& interpreter) const
|
Value AssignmentExpression::execute(Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
AK::Function<void(Value)> commit;
|
|
||||||
if (m_lhs->is_identifier()) {
|
|
||||||
commit = [&](Value value) {
|
|
||||||
auto name = static_cast<const Identifier&>(*m_lhs).string();
|
|
||||||
interpreter.set_variable(name, value);
|
|
||||||
};
|
|
||||||
} else if (m_lhs->is_member_expression()) {
|
|
||||||
commit = [&](Value value) {
|
|
||||||
if (auto* object = static_cast<const MemberExpression&>(*m_lhs).object().execute(interpreter).to_object(interpreter.heap())) {
|
|
||||||
auto property_name = static_cast<const MemberExpression&>(*m_lhs).computed_property_name(interpreter);
|
|
||||||
object->put(property_name, value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto rhs_result = m_rhs->execute(interpreter);
|
auto rhs_result = m_rhs->execute(interpreter);
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
|
@ -690,7 +673,19 @@ Value AssignmentExpression::execute(Interpreter& interpreter) const
|
||||||
}
|
}
|
||||||
if (interpreter.exception())
|
if (interpreter.exception())
|
||||||
return {};
|
return {};
|
||||||
commit(rhs_result);
|
|
||||||
|
if (m_lhs->is_identifier()) {
|
||||||
|
auto name = static_cast<const Identifier&>(*m_lhs).string();
|
||||||
|
interpreter.set_variable(name, rhs_result);
|
||||||
|
} else if (m_lhs->is_member_expression()) {
|
||||||
|
if (auto* object = static_cast<const MemberExpression&>(*m_lhs).object().execute(interpreter).to_object(interpreter.heap())) {
|
||||||
|
auto property_name = static_cast<const MemberExpression&>(*m_lhs).computed_property_name(interpreter);
|
||||||
|
object->put(property_name, rhs_result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
return rhs_result;
|
return rhs_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue