Skip to content

Commit 5b96dda

Browse files
authored
chore: don't build an inspector stack (#11154)
1 parent 78c9ff4 commit 5b96dda

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

crates/evm/evm/src/inspectors/stack.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl InspectorStackRefMut<'_> {
643643
self.inner_context_data = Some(InnerContextData { original_origin: cached_env.tx.caller });
644644
self.in_inner_context = true;
645645

646-
let res = self.with_stack(|inspector| {
646+
let res = self.with_inspector(|inspector| {
647647
let (db, journal, env) = ecx.as_db_env_and_journal();
648648
let mut evm = new_evm_with_inspector(db, env.to_owned(), inspector);
649649

@@ -740,23 +740,22 @@ impl InspectorStackRefMut<'_> {
740740
(InterpreterResult { result, output, gas }, address)
741741
}
742742

743-
/// Moves out of references, constructs an [`InspectorStack`] and runs the given closure with
744-
/// it.
745-
fn with_stack<O>(&mut self, f: impl FnOnce(&mut InspectorStack) -> O) -> O {
746-
let mut stack = InspectorStack {
747-
cheatcodes: self.cheatcodes.as_deref_mut().map(|cheats| {
748-
core::mem::replace(cheats, Cheatcodes::new(cheats.config.clone())).into()
749-
}),
750-
inner: std::mem::take(self.inner),
751-
};
743+
/// Moves out of references, constructs a new [`InspectorStackRefMut`] and runs the given
744+
/// closure with it.
745+
fn with_inspector<O>(&mut self, f: impl FnOnce(InspectorStackRefMut<'_>) -> O) -> O {
746+
let mut cheatcodes = self
747+
.cheatcodes
748+
.as_deref_mut()
749+
.map(|cheats| core::mem::replace(cheats, Cheatcodes::new(cheats.config.clone())));
750+
let mut inner = std::mem::take(self.inner);
752751

753-
let out = f(&mut stack);
752+
let out = f(InspectorStackRefMut { cheatcodes: cheatcodes.as_mut(), inner: &mut inner });
754753

755754
if let Some(cheats) = self.cheatcodes.as_deref_mut() {
756-
*cheats = *stack.cheatcodes.take().unwrap();
755+
*cheats = cheatcodes.unwrap();
757756
}
758757

759-
*self.inner = stack.inner;
758+
*self.inner = inner;
760759

761760
out
762761
}

0 commit comments

Comments
 (0)