From ee2aef31ad722958aa8bbe021c700b34ad83834e Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Sun, 23 Jan 2022 12:27:17 +0100 Subject: [PATCH] Adjust `compile` and `execute` to avoid clones --- boa/benches/full.rs | 8 ++++---- boa/src/context.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/boa/benches/full.rs b/boa/benches/full.rs index c2eedd22731..efa7c25a159 100644 --- a/boa/benches/full.rs +++ b/boa/benches/full.rs @@ -36,7 +36,7 @@ macro_rules! full_benchmarks { let statement_list = Parser::new(CODE.as_bytes(), false).parse_all( &mut interner).expect("parsing failed"); c.bench_function(concat!($id, " (Compiler)"), move |b| { b.iter(|| { - Context::compile(black_box(statement_list.clone())); + Context::compile(black_box(&statement_list)); }) }); } @@ -47,9 +47,9 @@ macro_rules! full_benchmarks { { static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js")); let mut interner = Interner::new(); - let statement_list = Parser::new(CODE.as_bytes(), false).parse_all( &mut interner).expect("parsing failed"); - let code_block = Context::compile(statement_list); - let mut context = Context::default(); + let statement_list = Parser::new(CODE.as_bytes(), false).parse_all(&mut interner).expect("parsing failed"); + let mut context = Context::new(interner); + let code_block = Context::compile(&statement_list); c.bench_function(concat!($id, " (Execution)"), move |b| { b.iter(|| { context.execute(black_box(code_block.clone())).unwrap(); diff --git a/boa/src/context.rs b/boa/src/context.rs index e940c5de138..48734b629ed 100644 --- a/boa/src/context.rs +++ b/boa/src/context.rs @@ -895,7 +895,7 @@ impl Context { Err(e) => return self.throw_syntax_error(e), }; - let code_block = Context::compile(statement_list); + let code_block = Context::compile(&statement_list); let result = self.execute(code_block); // The main_timer needs to be dropped before the BoaProfiler is. @@ -907,22 +907,22 @@ impl Context { // Compile the AST into a CodeBlock ready to execute by the VM #[inline] - pub fn compile(statement_list: StatementList) -> CodeBlock { + pub fn compile(statement_list: &StatementList) -> Gc { let _ = BoaProfiler::global().start_event("Compilation", "Main"); let mut compiler = ByteCompiler::new(JsString::new("
"), statement_list.strict()); - compiler.compile_statement_list(&statement_list, true); - compiler.finish() + compiler.compile_statement_list(statement_list, true); + Gc::new(compiler.finish()) } // Call the VM with the codeblock and return the result #[inline] - pub fn execute(&mut self, code_block: CodeBlock) -> JsResult { + pub fn execute(&mut self, code_block: Gc) -> JsResult { let _ = BoaProfiler::global().start_event("Execute", "Main"); let global_object = self.global_object().into(); self.vm.push_frame(CallFrame { prev: None, - code: Gc::new(code_block), + code: code_block, this: global_object, pc: 0, catch: Vec::new(),