Browse Source

Optimize `Swap` opcode (#3027)

pull/3029/head
raskad 1 year ago committed by GitHub
parent
commit
ef4d9f6f00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      boa_engine/src/vm/opcode/swap/mod.rs

8
boa_engine/src/vm/opcode/swap/mod.rs

@ -15,11 +15,9 @@ impl Operation for Swap {
const INSTRUCTION: &'static str = "INST - Swap"; const INSTRUCTION: &'static str = "INST - Swap";
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let first = context.vm.pop(); let len = context.vm.stack.len();
let second = context.vm.pop(); assert!(len > 1);
context.vm.stack.swap(len - 1, len - 2);
context.vm.push(first);
context.vm.push(second);
Ok(CompletionType::Normal) Ok(CompletionType::Normal)
} }
} }

Loading…
Cancel
Save