Skip to content

Commit

Permalink
Adjust compile and execute to avoid clones
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jan 12, 2022
1 parent 2300d87 commit a09ebbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions boa/benches/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ macro_rules! full_benchmarks {
let statement_list = parse(CODE, false).unwrap();
c.bench_function(concat!($id, " (Compiler)"), move |b| {
b.iter(|| {
Context::compile(black_box(statement_list.clone()));
Context::compile(black_box(&statement_list));
})
});
}
Expand All @@ -44,7 +44,7 @@ macro_rules! full_benchmarks {
{
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
let statement_list = parse(CODE, false).unwrap();
let code_block = Context::compile(statement_list);
let code_block = Context::compile(&statement_list);
let mut context = Context::new();
c.bench_function(concat!($id, " (Execution)"), move |b| {
b.iter(|| {
Expand Down
12 changes: 6 additions & 6 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,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.
Expand All @@ -879,22 +879,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<CodeBlock> {
let _ = BoaProfiler::global().start_event("Compilation", "Main");
let mut compiler = ByteCompiler::new(JsString::new("<main>"), 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<JsValue> {
pub fn execute(&mut self, code_block: Gc<CodeBlock>) -> JsResult<JsValue> {
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(),
Expand Down

0 comments on commit a09ebbc

Please sign in to comment.