Skip to content

Commit

Permalink
Removed .clone() in ExecutionHandler::call, and reusing output buffer…
Browse files Browse the repository at this point in the history
… in Interpreter (#1512)
  • Loading branch information
impactdni2 authored Jun 11, 2024
1 parent d008720 commit 0768ec6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions crates/interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,24 @@ impl Interpreter {
call_outcome: CallOutcome,
) {
self.instruction_result = InstructionResult::Continue;
self.return_data_buffer.clone_from(call_outcome.output());

let out_offset = call_outcome.memory_start();
let out_len = call_outcome.memory_length();
let out_ins_result = *call_outcome.instruction_result();
let out_gas = call_outcome.gas();
self.return_data_buffer = call_outcome.result.output;

let target_len = min(out_len, self.return_data_buffer.len());
match call_outcome.instruction_result() {
match out_ins_result {
return_ok!() => {
// return unspend gas.
let remaining = call_outcome.gas().remaining();
let refunded = call_outcome.gas().refunded();
self.gas.erase_cost(remaining);
self.gas.record_refund(refunded);
self.gas.erase_cost(out_gas.remaining());
self.gas.record_refund(out_gas.refunded());
shared_memory.set(out_offset, &self.return_data_buffer[..target_len]);
push!(self, U256::from(1));
}
return_revert!() => {
self.gas.erase_cost(call_outcome.gas().remaining());
self.gas.erase_cost(out_gas.remaining());
shared_memory.set(out_offset, &self.return_data_buffer[..target_len]);
push!(self, U256::ZERO);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a, EXT, DB: Database> ExecutionHandler<'a, EXT, DB> {
context: &mut Context<EXT, DB>,
inputs: Box<CallInputs>,
) -> Result<FrameOrResult, EVMError<DB::Error>> {
(self.call)(context, inputs.clone())
(self.call)(context, inputs)
}

/// Call registered handler for call return.
Expand Down

0 comments on commit 0768ec6

Please sign in to comment.