@@ -66,7 +66,7 @@ impl OutputMode {
66
66
}
67
67
68
68
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Default ) ]
69
- pub struct CommandCacheKey {
69
+ pub struct CommandFingerprint {
70
70
program : OsString ,
71
71
args : Vec < OsString > ,
72
72
envs : Vec < ( OsString , Option < OsString > ) > ,
@@ -80,11 +80,11 @@ pub struct CommandProfile {
80
80
81
81
#[ derive( Default ) ]
82
82
pub struct CommandProfiler {
83
- stats : Mutex < HashMap < CommandCacheKey , CommandProfile > > ,
83
+ stats : Mutex < HashMap < CommandFingerprint , CommandProfile > > ,
84
84
}
85
85
86
86
impl CommandProfiler {
87
- pub fn record_execution ( & self , key : CommandCacheKey , start_time : Instant ) {
87
+ pub fn record_execution ( & self , key : CommandFingerprint , start_time : Instant ) {
88
88
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
89
89
let entry = stats. entry ( key) . or_default ( ) ;
90
90
entry. traces . push ( ExecutionTrace :: Executed {
@@ -93,7 +93,7 @@ impl CommandProfiler {
93
93
} ) ;
94
94
}
95
95
96
- pub fn record_cache_hit ( & self , key : CommandCacheKey ) {
96
+ pub fn record_cache_hit ( & self , key : CommandFingerprint ) {
97
97
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
98
98
let entry = stats. entry ( key) . or_default ( ) ;
99
99
entry. traces . push ( ExecutionTrace :: CacheHit { timestamp : Instant :: now ( ) } ) ;
@@ -113,27 +113,24 @@ impl CommandProfiler {
113
113
match trace {
114
114
ExecutionTrace :: CacheHit { timestamp } => {
115
115
hits += 1 ;
116
- println ! ( " - Cache hit at: { :?}" , timestamp ) ;
116
+ println ! ( " - Cache hit at: {timestamp :?}" ) ;
117
117
}
118
118
ExecutionTrace :: Executed { duration, timestamp } => {
119
119
runs += 1 ;
120
- if max_duration. map_or ( true , |d| * duration > d) {
120
+ if max_duration. is_none_or ( |d| * duration > d) {
121
121
max_duration = Some ( * duration) ;
122
122
}
123
- println ! ( " - Executed at: { :?}, duration: {:.2?}" , timestamp , duration ) ;
123
+ println ! ( " - Executed at: {timestamp :?}, duration: {duration :.2?}" ) ;
124
124
}
125
125
}
126
126
}
127
127
128
128
let duration_str = match max_duration {
129
- Some ( d) => format ! ( "{:.2?}" , d ) ,
129
+ Some ( d) => format ! ( "{d :.2?}" ) ,
130
130
None => "-" . into ( ) ,
131
131
} ;
132
132
133
- println ! (
134
- " => Summary: {} run(s), {} hit(s), max_duration={}" ,
135
- runs, hits, duration_str
136
- ) ;
133
+ println ! ( "Summary: {runs} run(s), {hits} hit(s), max_duration={duration_str}" ) ;
137
134
}
138
135
}
139
136
}
@@ -316,9 +313,9 @@ impl<'a> BootstrapCommand {
316
313
}
317
314
}
318
315
319
- pub fn cache_key ( & self ) -> CommandCacheKey {
316
+ pub fn cache_key ( & self ) -> CommandFingerprint {
320
317
let command = & self . command ;
321
- CommandCacheKey {
318
+ CommandFingerprint {
322
319
program : command. get_program ( ) . into ( ) ,
323
320
args : command. get_args ( ) . map ( OsStr :: to_os_string) . collect ( ) ,
324
321
envs : command
@@ -505,7 +502,7 @@ pub struct ExecutionContext {
505
502
506
503
#[ derive( Default ) ]
507
504
pub struct CommandCache {
508
- cache : Mutex < HashMap < CommandCacheKey , CommandOutput > > ,
505
+ cache : Mutex < HashMap < CommandFingerprint , CommandOutput > > ,
509
506
}
510
507
511
508
enum CommandState < ' a > {
@@ -516,7 +513,7 @@ enum CommandState<'a> {
516
513
stdout : OutputMode ,
517
514
stderr : OutputMode ,
518
515
executed_at : & ' a Location < ' a > ,
519
- cache_key : CommandCacheKey ,
516
+ cache_key : CommandFingerprint ,
520
517
start_time : Instant ,
521
518
} ,
522
519
}
@@ -533,11 +530,11 @@ pub struct DeferredCommand<'a> {
533
530
}
534
531
535
532
impl CommandCache {
536
- pub fn get ( & self , key : & CommandCacheKey ) -> Option < CommandOutput > {
533
+ pub fn get ( & self , key : & CommandFingerprint ) -> Option < CommandOutput > {
537
534
self . cache . lock ( ) . unwrap ( ) . get ( key) . cloned ( )
538
535
}
539
536
540
- pub fn insert ( & self , key : CommandCacheKey , output : CommandOutput ) {
537
+ pub fn insert ( & self , key : CommandFingerprint , output : CommandOutput ) {
541
538
self . cache . lock ( ) . unwrap ( ) . insert ( key, output) ;
542
539
}
543
540
}
0 commit comments