1
1
use std:: borrow:: Cow ;
2
2
use std:: process:: ExitCode ;
3
- use std:: sync:: OnceLock ;
3
+ use std:: sync:: LazyLock ;
4
4
use std:: { env, fs} ;
5
5
6
6
use regex:: { Regex , RegexBuilder } ;
@@ -151,8 +151,7 @@ impl CommandKind {
151
151
}
152
152
}
153
153
154
- static LINE_PATTERN : OnceLock < Regex > = OnceLock :: new ( ) ;
155
- fn line_pattern ( ) -> Regex {
154
+ static LINE_PATTERN : LazyLock < Regex > = LazyLock :: new ( || {
156
155
RegexBuilder :: new (
157
156
r#"
158
157
//@\s+
@@ -165,7 +164,7 @@ fn line_pattern() -> Regex {
165
164
. unicode ( true )
166
165
. build ( )
167
166
. unwrap ( )
168
- }
167
+ } ) ;
169
168
170
169
fn print_err ( msg : & str , lineno : usize ) {
171
170
eprintln ! ( "Invalid command: {} on line {}" , msg, lineno)
@@ -184,21 +183,17 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
184
183
for ( lineno, line) in file. split ( '\n' ) . enumerate ( ) {
185
184
let lineno = lineno + 1 ;
186
185
187
- let cap = match LINE_PATTERN . get_or_init ( line_pattern) . captures ( line) {
188
- Some ( c) => c,
189
- None => continue ,
186
+ let Some ( cap) = LINE_PATTERN . captures ( line) else {
187
+ continue ;
190
188
} ;
191
189
192
- let negated = cap. name ( "negated" ) . unwrap ( ) . as_str ( ) == "!" ;
190
+ let negated = & cap[ "negated" ] == "!" ;
193
191
194
192
let args_str = & cap[ "args" ] ;
195
- let args = match shlex:: split ( args_str) {
196
- Some ( args) => args,
197
- None => {
198
- print_err ( & format ! ( "Invalid arguments to shlex::split: `{args_str}`" , ) , lineno) ;
199
- errors = true ;
200
- continue ;
201
- }
193
+ let Some ( args) = shlex:: split ( args_str) else {
194
+ print_err ( & format ! ( "Invalid arguments to shlex::split: `{args_str}`" , ) , lineno) ;
195
+ errors = true ;
196
+ continue ;
202
197
} ;
203
198
204
199
if let Some ( ( kind, path) ) = CommandKind :: parse ( & cap[ "cmd" ] , negated, & args) {
0 commit comments