Skip to content

Commit

Permalink
chore(interpreter): unbox contract field (bluealloy#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 26, 2024
1 parent 89792c2 commit 52c8f92
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use revm_primitives::U256;
use std::borrow::ToOwned;
use std::boxed::Box;

/// EVM bytecode interpreter.
#[derive(Debug)]
pub struct Interpreter {
/// Contract information and invoking data
pub contract: Box<Contract>,
pub contract: Contract,
/// The current instruction pointer.
pub instruction_pointer: *const u8,
/// The execution control flag. If this is not set to `Continue`, the interpreter will stop
Expand Down Expand Up @@ -114,7 +115,7 @@ impl InterpreterAction {

impl Interpreter {
/// Create new interpreter
pub fn new(contract: Box<Contract>, gas_limit: u64, is_static: bool) -> Self {
pub fn new(contract: Contract, gas_limit: u64, is_static: bool) -> Self {
Self {
instruction_pointer: contract.bytecode.as_ptr(),
contract,
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn bench_eval(g: &mut BenchmarkGroup<'_, WallTime>, evm: &mut Evm<'static, (), B
// replace memory with empty memory to use it inside interpreter.
// Later return memory back.
let temp = core::mem::replace(&mut shared_memory, EMPTY_SHARED_MEMORY);
let mut interpreter = Interpreter::new(Box::new(contract.clone()), u64::MAX, false);
let mut interpreter = Interpreter::new(contract.clone(), u64::MAX, false);
let res = interpreter.run(temp, &instruction_table, &mut host);
shared_memory = interpreter.take_memory();
host.clear();
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/context/evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ impl<DB: Database> EvmContext<DB> {
inputs.return_memory_offset.clone(),
))
} else if !bytecode.is_empty() {
let contract = Box::new(Contract::new_with_context(
let contract = Contract::new_with_context(
inputs.input.clone(),
bytecode,
code_hash,
&inputs.context,
));
);
// Create interpreter and executes call and push new CallStackFrame.
Ok(FrameOrResult::new_call_frame(
inputs.return_memory_offset.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/context/inner_evm_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ impl<DB: Database> InnerEvmContext<DB> {

let bytecode = Bytecode::new_raw(inputs.init_code.clone());

let contract = Box::new(Contract::new(
let contract = Contract::new(
Bytes::new(),
bytecode,
init_code_hash,
created_address,
inputs.caller,
inputs.value,
));
);

Ok(FrameOrResult::new_create_frame(
created_address,
Expand Down

0 comments on commit 52c8f92

Please sign in to comment.