Skip to content

Commit

Permalink
Use Swap opcode if possible instead of RotateLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 30, 2022
1 parent 2e32193 commit 2e6f543
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,13 @@ impl<'b> ByteCompiler<'b> {
// The wrap is needed so it can match the function signature.
#[allow(clippy::unnecessary_wraps)]
fn access_set_top_of_stack_expr_fn(compiler: &mut ByteCompiler<'_>, level: u8) -> JsResult<()> {
if level != 0 {
compiler.emit_opcode(Opcode::RotateLeft);
compiler.emit_u8(level + 1);
match level {
0 => {}
1 => compiler.emit_opcode(Opcode::Swap),
_ => {
compiler.emit_opcode(Opcode::RotateLeft);
compiler.emit_u8(level + 1);
}
}
Ok(())
}
Expand Down

0 comments on commit 2e6f543

Please sign in to comment.