From bda8fcdf972cf0b33e666e9681f6f012460b3912 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sat, 10 Jun 2023 00:15:46 +0200 Subject: [PATCH] Remove Cell and comments --- boa_engine/src/bytecompiler/function.rs | 2 +- boa_engine/src/bytecompiler/mod.rs | 12 ++++++------ boa_engine/src/vm/code_block.rs | 6 +++--- boa_engine/src/vm/flowgraph/mod.rs | 2 +- boa_engine/src/vm/mod.rs | 2 +- boa_engine/src/vm/opcode/get/property.rs | 14 -------------- boa_engine/src/vm/opcode/set/property.rs | 8 -------- 7 files changed, 12 insertions(+), 34 deletions(-) diff --git a/boa_engine/src/bytecompiler/function.rs b/boa_engine/src/bytecompiler/function.rs index eec5456b00b..a1e055a794b 100644 --- a/boa_engine/src/bytecompiler/function.rs +++ b/boa_engine/src/bytecompiler/function.rs @@ -152,7 +152,7 @@ impl FunctionCompiler { if compiler .bytecode .last() - .filter(|last| **last == (Opcode::Return as u8).into()) + .filter(|last| **last == Opcode::Return as u8) .is_none() { compiler.emit_opcode(Opcode::PushUndefined); diff --git a/boa_engine/src/bytecompiler/mod.rs b/boa_engine/src/bytecompiler/mod.rs index 3b9ade630c4..d73a1dd3e1a 100644 --- a/boa_engine/src/bytecompiler/mod.rs +++ b/boa_engine/src/bytecompiler/mod.rs @@ -226,7 +226,7 @@ pub struct ByteCompiler<'ctx, 'host> { pub(crate) params: FormalParameterList, /// Bytecode - pub(crate) bytecode: Vec>, + pub(crate) bytecode: Vec, /// Literals pub(crate) literals: Vec, @@ -429,15 +429,15 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> { } fn emit_u64(&mut self, value: u64) { - self.bytecode.extend(value.to_ne_bytes().map(Cell::new)); + self.bytecode.extend(value.to_ne_bytes()); } fn emit_u32(&mut self, value: u32) { - self.bytecode.extend(value.to_ne_bytes().map(Cell::new)); + self.bytecode.extend(value.to_ne_bytes()); } fn emit_u16(&mut self, value: u16) { - self.bytecode.extend(value.to_ne_bytes().map(Cell::new)); + self.bytecode.extend(value.to_ne_bytes()); } pub(crate) fn emit_opcode(&mut self, opcode: Opcode) { @@ -445,7 +445,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> { } fn emit_u8(&mut self, value: u8) { - self.bytecode.push(Cell::new(value)); + self.bytecode.push(value); } fn emit_push_integer(&mut self, value: i32) { @@ -550,7 +550,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> { let Label { index } = label; let index = index as usize; - let bytes = target.to_ne_bytes().map(Cell::new); + let bytes = target.to_ne_bytes(); // This is done to avoid unneeded bounds checks. assert!(self.bytecode.len() > index + U32_SIZE && usize::MAX - U32_SIZE >= index); diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 56f0600d8cf..c0fd527b85e 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -168,7 +168,7 @@ pub struct CodeBlock { /// Bytecode #[unsafe_ignore_trace] - pub(crate) bytecode: Box<[Cell]>, + pub(crate) bytecode: Box<[u8]>, /// Literals pub(crate) literals: Box<[JsValue]>, @@ -318,7 +318,7 @@ impl CodeBlock { /// Returns an empty `String` if no operands are present. #[cfg(any(feature = "trace", feature = "flowgraph"))] pub(crate) fn instruction_operands(&self, pc: &mut usize, interner: &Interner) -> String { - let opcode: Opcode = self.bytecode[*pc].get().into(); + let opcode: Opcode = self.bytecode[*pc].into(); *pc += size_of::(); match opcode { Opcode::SetFunctionName => { @@ -705,7 +705,7 @@ impl ToInternedString for CodeBlock { let mut pc = 0; let mut count = 0; while pc < self.bytecode.len() { - let opcode: Opcode = self.bytecode[pc].get().into(); + let opcode: Opcode = self.bytecode[pc].into(); let opcode = opcode.as_str(); let previous_pc = pc; let operands = self.instruction_operands(&mut pc, interner); diff --git a/boa_engine/src/vm/flowgraph/mod.rs b/boa_engine/src/vm/flowgraph/mod.rs index ceed2a02ff7..b93d64da635 100644 --- a/boa_engine/src/vm/flowgraph/mod.rs +++ b/boa_engine/src/vm/flowgraph/mod.rs @@ -32,7 +32,7 @@ impl CodeBlock { let mut pc = 0; while pc < self.bytecode.len() { - let opcode: Opcode = self.bytecode[pc].get().into(); + let opcode: Opcode = self.bytecode[pc].into(); let opcode_str = opcode.as_str(); let previous_pc = pc; diff --git a/boa_engine/src/vm/mod.rs b/boa_engine/src/vm/mod.rs index f9c877ddb9f..c2a8314a7a3 100644 --- a/boa_engine/src/vm/mod.rs +++ b/boa_engine/src/vm/mod.rs @@ -168,7 +168,7 @@ impl Context<'_> { let frame = self.vm.frame_mut(); let pc = frame.pc; - let opcode = Opcode::from(frame.code_block.bytecode[pc as usize].get()); + let opcode = Opcode::from(frame.code_block.bytecode[pc as usize]); frame.pc += 1; opcode }; diff --git a/boa_engine/src/vm/opcode/get/property.rs b/boa_engine/src/vm/opcode/get/property.rs index a4a870b7b13..03b444d36c0 100644 --- a/boa_engine/src/vm/opcode/get/property.rs +++ b/boa_engine/src/vm/opcode/get/property.rs @@ -31,12 +31,6 @@ impl Operation for GetPropertyByName { if slot.is_cachable() { let object_borrowed = object.borrow(); if ic.matches(object_borrowed.shape()) { - // println!( - // "GET: T: \"{}\" {}: {:?}", - // ic.name.to_std_string_escaped(), - // slot.index, - // slot.attributes - // ); let mut result = if slot.attributes.contains(SlotAttributes::PROTOTYPE) { let prototype = object .borrow() @@ -70,14 +64,6 @@ impl Operation for GetPropertyByName { slot = *context.slot(); - // println!( - // "GET: F: \"{}\" {}: {:?} - {}", - // key, - // slot.index, - // slot.attributes, - // result.type_of() - // ); - // Cache the property. if slot.attributes.is_cachable() { let ic = &context.vm.frame().code_block.ic[ic_index]; diff --git a/boa_engine/src/vm/opcode/set/property.rs b/boa_engine/src/vm/opcode/set/property.rs index d5acf5328ee..9d0417b0f73 100644 --- a/boa_engine/src/vm/opcode/set/property.rs +++ b/boa_engine/src/vm/opcode/set/property.rs @@ -36,12 +36,6 @@ impl Operation for SetPropertyByName { if slot.is_cachable() { let object_borrowed = object.borrow(); if ic.matches(object_borrowed.shape()) { - // println!( - // "SET: T: \"{}\" {}: {:?}", - // ic.name.to_std_string_escaped(), - // slot.index, - // slot.attributes - // ); let slot_index = slot.index as usize; if slot.attributes.is_accessor_descriptor() { @@ -97,8 +91,6 @@ impl Operation for SetPropertyByName { slot = *context.slot(); - // println!("SET: F: \"{}\" {}: {:?}", name, slot.index, slot.attributes); - // Cache the property. if succeeded && slot.is_cachable() { let ic = &context.vm.frame().code_block.ic[ic_index];