diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-05 19:21:36 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-06 08:26:26 +0200 |
commit | 6e7713a5f4bda99db6ecb809951d235f46bdd59e (patch) | |
tree | 50a55dd4765ae32deb3e42de2d2d688494fdf209 /Libraries | |
parent | 76bb0fab2d6a45962a5fdc2ba54e6c5c6e1c630c (diff) | |
download | serenity-6e7713a5f4bda99db6ecb809951d235f46bdd59e.zip |
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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/AST.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 8bd75e4a90..be00893918 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -651,23 +651,6 @@ void Identifier::dump(int indent) 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); if (interpreter.exception()) return {}; @@ -690,7 +673,19 @@ Value AssignmentExpression::execute(Interpreter& interpreter) const } if (interpreter.exception()) 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; } |