File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use std::fs::OpenOptions;
12
12
use std:: io:: Write ;
13
13
use std:: process:: Command ;
14
14
use std:: str:: FromStr ;
15
+ use std:: sync:: Once ;
15
16
16
17
#[ cfg( test) ]
17
18
mod tests;
@@ -65,9 +66,21 @@ pub fn exe(name: &str, target: &str) -> String {
65
66
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
66
67
#[ inline( always) ]
67
68
pub fn parse_rustc_verbose ( ) -> usize {
68
- match env:: var ( "RUSTC_VERBOSE" ) {
69
- Ok ( s) => usize:: from_str ( & s) . expect ( "RUSTC_VERBOSE should be an integer" ) ,
70
- Err ( _) => 0 ,
69
+ static mut VERBOSITY : usize = 0 ;
70
+ static INIT : Once = Once :: new ( ) ;
71
+
72
+ // SAFETY: Write only happens once.
73
+ unsafe {
74
+ // Result of this function never changes, so cache it to avoid recomputing
75
+ // it repeatedly as it’s called thousands of times from the rustc shim.
76
+ INIT . call_once ( || {
77
+ VERBOSITY = match env:: var ( "RUSTC_VERBOSE" ) {
78
+ Ok ( s) => usize:: from_str ( & s) . expect ( "RUSTC_VERBOSE should be an integer" ) ,
79
+ Err ( _) => 0 ,
80
+ } ;
81
+ } ) ;
82
+
83
+ VERBOSITY
71
84
}
72
85
}
73
86
You can’t perform that action at this time.
0 commit comments