Forráskód Böngészése

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.
Andreas Kling 5 éve
szülő
commit
6e7713a5f4
1 módosított fájl, 13 hozzáadás és 18 törlés
  1. 13 18
      Libraries/LibJS/AST.cpp

+ 13 - 18
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;
 }