Browse Source

LibJS/Bytecode: Allow assignment expression to write directly to locals

Andreas Kling 1 year ago
parent
commit
ce7c925924
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

+ 6 - 1
Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

@@ -642,7 +642,12 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> AssignmentExpression::g
         return TRY(m_rhs->generate_bytecode(generator)).value();
         return TRY(m_rhs->generate_bytecode(generator)).value();
     }());
     }());
 
 
-    auto dst = choose_dst(generator, preferred_dst);
+    // OPTIMIZATION: If LHS is a local, we can write the result directly into it.
+    auto dst = [&] {
+        if (lhs.operand().is_local())
+            return lhs;
+        return choose_dst(generator, preferred_dst);
+    }();
 
 
     switch (m_op) {
     switch (m_op) {
     case AssignmentOp::AdditionAssignment:
     case AssignmentOp::AdditionAssignment: