From 69cc64e94c831766d3398e866e58b6293d1c655b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 6 May 2024 09:34:42 +0200 Subject: [PATCH] LibJS/Bytecode: Emit `for` condition check before update statement This allows jump elision to eliminate an unnecessary jump since things now get laid out naturally in memory (normal execution order). --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index d6b070ab3c1..e6c2f43bff6 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -888,16 +888,16 @@ Bytecode::CodeGenerationErrorOr> ForStatement::gener body_block_ptr = &generator.make_block(); - if (m_test) - test_block_ptr = &generator.make_block(); - else - test_block_ptr = body_block_ptr; - if (m_update) update_block_ptr = &generator.make_block(); else update_block_ptr = body_block_ptr; + if (m_test) + test_block_ptr = &generator.make_block(); + else + test_block_ptr = body_block_ptr; + generator.emit(Bytecode::Label { *test_block_ptr }); if (m_test) {