Skip to content

Commit

Permalink
style: reuse empty initialized var on return val
Browse files Browse the repository at this point in the history
  • Loading branch information
boolafish committed Oct 9, 2024
1 parent e526f55 commit dfc75d0
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions crates/cheatcodes/src/evm/record_debug_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,31 @@ fn get_memory_input_for_opcode(
stack: Option<&Vec<U256>>,
memory: Option<&RecordedMemory>,
) -> Bytes {
let Some(stack_data) = stack else { return Bytes::new() };
let Some(memory_data) = memory else { return Bytes::new() };
let mut memory_input = Bytes::new();
let Some(stack_data) = stack else { return memory_input };
let Some(memory_data) = memory else { return memory_input };

if let Some(accesses) = get_buffer_accesses(opcode, stack_data) {
if let Some((kind, access)) = accesses.read {
return match kind {
BufferKind::Memory => {
get_slice_from_memory(memory_data.as_bytes(), access.offset, access.len)
}
_ => Bytes::new(),
if let BufferKind::Memory = kind {
memory_input =
get_slice_from_memory(memory_data.as_bytes(), access.offset, access.len);
}
}
};

Bytes::new()
memory_input
}

// The expected `stack` here is from the trace stack, where the top of the stack
// is the last value of the vector
fn get_stack_inputs_for_opcode(opcode: u8, stack: Option<&Vec<U256>>) -> Vec<U256> {
let Some(op) = OpCode::new(opcode) else {
// unknown opcode
return vec![]
};
let mut inputs = Vec::new();

let Some(stack_data) = stack else { return vec![] };
let Some(op) = OpCode::new(opcode) else { return inputs };
let Some(stack_data) = stack else { return inputs };

let stack_input_size = op.inputs() as usize;
let mut inputs = Vec::new();
for i in 0..stack_input_size {
inputs.push(stack_data[stack_data.len() - 1 - i]);
}
Expand Down

0 comments on commit dfc75d0

Please sign in to comment.