@@ -262,7 +262,7 @@ pub struct InspectorData {
262262 pub traces : Option < SparsedTraceArena > ,
263263 pub line_coverage : Option < HitMaps > ,
264264 pub edge_coverage : Option < Vec < u8 > > ,
265- pub cheatcodes : Option < Box < Cheatcodes > > ,
265+ pub cheatcodes : Option < Cheatcodes > ,
266266 pub chisel_state : Option < ( Vec < U256 > , Vec < u8 > , Option < InstructionResult > ) > ,
267267 pub reverter : Option < Address > ,
268268}
@@ -290,7 +290,7 @@ pub struct InnerContextData {
290290/// collection, etc.
291291#[ derive( Clone , Debug , Default ) ]
292292pub struct InspectorStack {
293- pub cheatcodes : Option < Box < Cheatcodes > > ,
293+ pub cheatcodes : Option < Cheatcodes > ,
294294 pub inner : InspectorStackInner ,
295295}
296296
@@ -300,17 +300,15 @@ pub struct InspectorStack {
300300#[ derive( Default , Clone , Debug ) ]
301301pub struct InspectorStackInner {
302302 // Inspectors.
303- // These are boxed to reduce the size of the struct and slightly improve performance of the
304- // `if let Some` checks.
305- pub chisel_state : Option < Box < ChiselState > > ,
306- pub edge_coverage : Option < Box < EdgeCovInspector > > ,
307- pub fuzzer : Option < Box < Fuzzer > > ,
308- pub line_coverage : Option < Box < LineCoverageCollector > > ,
309- pub log_collector : Option < Box < LogCollector > > ,
310- pub printer : Option < Box < CustomPrintTracer > > ,
311- pub revert_diag : Option < Box < RevertDiagnostic > > ,
312- pub script_execution_inspector : Option < Box < ScriptExecutionInspector > > ,
313- pub tracer : Option < Box < TracingInspector > > ,
303+ pub chisel_state : Option < ChiselState > ,
304+ pub edge_coverage : Option < EdgeCovInspector > ,
305+ pub fuzzer : Option < Fuzzer > ,
306+ pub line_coverage : Option < LineCoverageCollector > ,
307+ pub log_collector : Option < LogCollector > ,
308+ pub printer : Option < CustomPrintTracer > ,
309+ pub revert_diag : Option < RevertDiagnostic > ,
310+ pub script_execution_inspector : Option < ScriptExecutionInspector > ,
311+ pub tracer : Option < TracingInspector > ,
314312
315313 // InspectorExt and other internal data.
316314 pub enable_isolation : bool ,
@@ -337,7 +335,7 @@ impl CheatcodesExecutor for InspectorStackInner {
337335 Box :: new ( InspectorStackRefMut { cheatcodes : Some ( cheats) , inner : self } )
338336 }
339337
340- fn tracing_inspector ( & mut self ) -> Option < & mut Option < Box < TracingInspector > > > {
338+ fn tracing_inspector ( & mut self ) -> Option < & mut Option < TracingInspector > > {
341339 Some ( & mut self . tracer )
342340 }
343341}
@@ -400,19 +398,19 @@ impl InspectorStack {
400398 /// Set the cheatcodes inspector.
401399 #[ inline]
402400 pub fn set_cheatcodes ( & mut self , cheatcodes : Cheatcodes ) {
403- self . cheatcodes = Some ( cheatcodes. into ( ) ) ;
401+ self . cheatcodes = Some ( cheatcodes) ;
404402 }
405403
406404 /// Set the fuzzer inspector.
407405 #[ inline]
408406 pub fn set_fuzzer ( & mut self , fuzzer : Fuzzer ) {
409- self . fuzzer = Some ( fuzzer. into ( ) ) ;
407+ self . fuzzer = Some ( fuzzer) ;
410408 }
411409
412410 /// Set the Chisel inspector.
413411 #[ inline]
414412 pub fn set_chisel ( & mut self , final_pc : usize ) {
415- self . chisel_state = Some ( ChiselState :: new ( final_pc) . into ( ) ) ;
413+ self . chisel_state = Some ( ChiselState :: new ( final_pc) ) ;
416414 }
417415
418416 /// Set whether to enable the line coverage collector.
@@ -424,8 +422,7 @@ impl InspectorStack {
424422 /// Set whether to enable the edge coverage collector.
425423 #[ inline]
426424 pub fn collect_edge_coverage ( & mut self , yes : bool ) {
427- // TODO: configurable edge size?
428- self . edge_coverage = yes. then ( EdgeCovInspector :: new) . map ( Into :: into) ;
425+ self . edge_coverage = yes. then ( EdgeCovInspector :: new) ; // TODO configurable edge size?
429426 }
430427
431428 /// Set whether to enable call isolation.
@@ -462,7 +459,11 @@ impl InspectorStack {
462459 /// Revert diagnostic inspector is activated when `mode != TraceMode::None`
463460 #[ inline]
464461 pub fn tracing ( & mut self , mode : TraceMode ) {
465- self . revert_diag = ( !mode. is_none ( ) ) . then ( RevertDiagnostic :: default) . map ( Into :: into) ;
462+ if mode. is_none ( ) {
463+ self . revert_diag = None ;
464+ } else {
465+ self . revert_diag = Some ( RevertDiagnostic :: default ( ) ) ;
466+ }
466467
467468 if let Some ( config) = mode. into_config ( ) {
468469 * self . tracer . get_or_insert_with ( Default :: default) . config_mut ( ) = config;
@@ -479,6 +480,7 @@ impl InspectorStack {
479480 }
480481
481482 /// Collects all the data gathered during inspection into a single struct.
483+ #[ inline]
482484 pub fn collect ( self ) -> InspectorData {
483485 let Self {
484486 mut cheatcodes,
@@ -529,7 +531,7 @@ impl InspectorStack {
529531
530532 #[ inline( always) ]
531533 fn as_mut ( & mut self ) -> InspectorStackRefMut < ' _ > {
532- InspectorStackRefMut { cheatcodes : self . cheatcodes . as_deref_mut ( ) , inner : & mut self . inner }
534+ InspectorStackRefMut { cheatcodes : self . cheatcodes . as_mut ( ) , inner : & mut self . inner }
533535 }
534536}
535537
@@ -738,16 +740,17 @@ impl InspectorStackRefMut<'_> {
738740 /// it.
739741 fn with_stack < O > ( & mut self , f : impl FnOnce ( & mut InspectorStack ) -> O ) -> O {
740742 let mut stack = InspectorStack {
741- cheatcodes : self . cheatcodes . as_deref_mut ( ) . map ( |cheats| {
742- core:: mem:: replace ( cheats, Cheatcodes :: new ( cheats. config . clone ( ) ) ) . into ( )
743- } ) ,
743+ cheatcodes : self
744+ . cheatcodes
745+ . as_deref_mut ( )
746+ . map ( |cheats| core:: mem:: replace ( cheats, Cheatcodes :: new ( cheats. config . clone ( ) ) ) ) ,
744747 inner : std:: mem:: take ( self . inner ) ,
745748 } ;
746749
747750 let out = f ( & mut stack) ;
748751
749752 if let Some ( cheats) = self . cheatcodes . as_deref_mut ( ) {
750- * cheats = * stack. cheatcodes . take ( ) . unwrap ( ) ;
753+ * cheats = stack. cheatcodes . take ( ) . unwrap ( ) ;
751754 }
752755
753756 * self . inner = stack. inner ;
@@ -788,11 +791,6 @@ impl InspectorStackRefMut<'_> {
788791 }
789792 }
790793
791- // We take extra care in optimizing `step` and `step_end`, as they're are likely the most
792- // hot functions in all of Foundry.
793- // We want to `#[inline(always)]` these functions so that `InspectorStack` does not
794- // delegate to `InspectorStackRefMut` in this case.
795-
796794 #[ inline( always) ]
797795 fn step_inlined (
798796 & mut self ,
@@ -801,18 +799,17 @@ impl InspectorStackRefMut<'_> {
801799 ) {
802800 call_inspectors ! (
803801 [
804- // These are sorted in definition order.
805- & mut self . edge_coverage,
806802 & mut self . fuzzer,
803+ & mut self . tracer,
807804 & mut self . line_coverage,
805+ & mut self . edge_coverage,
806+ & mut self . script_execution_inspector,
808807 & mut self . printer,
809808 & mut self . revert_diag,
810- & mut self . script_execution_inspector,
811- & mut self . tracer,
812809 // Keep `cheatcodes` last to make use of the tail call.
813810 & mut self . cheatcodes,
814811 ] ,
815- |inspector| ( * * inspector) . step( interpreter, ecx) ,
812+ |inspector| ( * inspector) . step( interpreter, ecx) ,
816813 ) ;
817814 }
818815
@@ -824,15 +821,14 @@ impl InspectorStackRefMut<'_> {
824821 ) {
825822 call_inspectors ! (
826823 [
827- // These are sorted in definition order.
824+ & mut self . tracer ,
828825 & mut self . chisel_state,
829826 & mut self . printer,
830827 & mut self . revert_diag,
831- & mut self . tracer,
832828 // Keep `cheatcodes` last to make use of the tail call.
833829 & mut self . cheatcodes,
834830 ] ,
835- |inspector| ( * * inspector) . step_end( interpreter, ecx) ,
831+ |inspector| ( * inspector) . step_end( interpreter, ecx) ,
836832 ) ;
837833 }
838834}
0 commit comments