فهرست منبع

LibJS/Bytecode: Avoid unnecessary copy of call expression callee

If the callee is already a temporary register, we don't need to copy it
to *another* temporary before evaluating arguments. None of the
arguments will clobber the existing temporary anyway.
Andreas Kling 1 سال پیش
والد
کامیت
96511a7d19
1فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 10 3
      Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

+ 10 - 3
Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

@@ -1652,9 +1652,16 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> CallExpression::generat
         original_callee = TRY(m_callee->generate_bytecode(generator)).value();
     }
 
-    // NOTE: We copy the callee to a new register to avoid overwriting it while evaluating arguments.
-    auto callee = generator.allocate_register();
-    generator.emit<Bytecode::Op::Mov>(callee, *original_callee);
+    // NOTE: If the callee isn't already a temporary, we copy it to a new register
+    //       to avoid overwriting it while evaluating arguments.
+    auto callee = [&]() -> ScopedOperand {
+        if (!original_callee->operand().is_register()) {
+            auto callee = generator.allocate_register();
+            generator.emit<Bytecode::Op::Mov>(callee, *original_callee);
+            return callee;
+        }
+        return *original_callee;
+    }();
 
     Bytecode::Op::CallType call_type;
     if (is<NewExpression>(*this)) {