From ce7c9259243ce68875bf1b8fa4bf2da9f51988c3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 14 May 2024 13:15:14 +0200 Subject: [PATCH] LibJS/Bytecode: Allow assignment expression to write directly to locals --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index a468c9cf8c3..c078fc9ac7b 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -642,7 +642,12 @@ Bytecode::CodeGenerationErrorOr> AssignmentExpression::g 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) { case AssignmentOp::AdditionAssignment: