@@ -30,7 +30,6 @@ use datafusion_expr::{
30
30
} ;
31
31
use itertools:: izip;
32
32
use regex:: Regex ;
33
- use std:: collections:: hash_map:: Entry ;
34
33
use std:: collections:: HashMap ;
35
34
use std:: sync:: { Arc , OnceLock } ;
36
35
@@ -549,19 +548,16 @@ where
549
548
}
550
549
}
551
550
552
- fn compile_and_cache_regex (
553
- regex : & str ,
554
- flags : Option < & str > ,
555
- regex_cache : & mut HashMap < String , Regex > ,
556
- ) -> Result < Regex , ArrowError > {
557
- match regex_cache. entry ( regex. to_string ( ) ) {
558
- Entry :: Vacant ( entry) => {
559
- let compiled = compile_regex ( regex, flags) ?;
560
- entry. insert ( compiled. clone ( ) ) ;
561
- Ok ( compiled)
562
- }
563
- Entry :: Occupied ( entry) => Ok ( entry. get ( ) . to_owned ( ) ) ,
551
+ fn compile_and_cache_regex < ' a > (
552
+ regex : & ' a str ,
553
+ flags : Option < & ' a str > ,
554
+ regex_cache : & ' a mut HashMap < String , Regex > ,
555
+ ) -> Result < & ' a Regex , ArrowError > {
556
+ if !regex_cache. contains_key ( regex) {
557
+ let compiled = compile_regex ( regex, flags) ?;
558
+ regex_cache. insert ( regex. to_string ( ) , compiled) ;
564
559
}
560
+ Ok ( regex_cache. get ( regex) . unwrap ( ) )
565
561
}
566
562
567
563
fn compile_regex ( regex : & str , flags : Option < & str > ) -> Result < Regex , ArrowError > {
0 commit comments