@@ -6,9 +6,9 @@ use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind};
6
6
use syntax:: hir:: literal:: Literals ;
7
7
use syntax:: hir:: Hir ;
8
8
use syntax:: ParserBuilder ;
9
- use thread_local:: CachedThreadLocal ;
10
9
11
10
use backtrack;
11
+ use cache:: { Cached , CachedGuard } ;
12
12
use compile:: Compiler ;
13
13
use dfa;
14
14
use error:: Error ;
@@ -32,7 +32,7 @@ pub struct Exec {
32
32
/// All read only state.
33
33
ro : Arc < ExecReadOnly > ,
34
34
/// Caches for the various matching engines.
35
- cache : CachedThreadLocal < ProgramCache > ,
35
+ cache : Cached < ProgramCache > ,
36
36
}
37
37
38
38
/// `ExecNoSync` is like `Exec`, except it embeds a reference to a cache. This
@@ -43,7 +43,7 @@ pub struct ExecNoSync<'c> {
43
43
/// All read only state.
44
44
ro : & ' c Arc < ExecReadOnly > ,
45
45
/// Caches for the various matching engines.
46
- cache : & ' c ProgramCache ,
46
+ cache : CachedGuard < ' c , ProgramCache > ,
47
47
}
48
48
49
49
/// `ExecNoSyncStr` is like `ExecNoSync`, but matches on &str instead of &[u8].
@@ -291,7 +291,7 @@ impl ExecBuilder {
291
291
ac : None ,
292
292
match_type : MatchType :: Nothing ,
293
293
} ) ;
294
- return Ok ( Exec { ro : ro, cache : CachedThreadLocal :: new ( ) } ) ;
294
+ return Ok ( Exec { ro : ro, cache : Cached :: new ( ) } ) ;
295
295
}
296
296
let parsed = self . parse ( ) ?;
297
297
let mut nfa = Compiler :: new ( )
@@ -347,7 +347,7 @@ impl ExecBuilder {
347
347
ro. match_type = ro. choose_match_type ( self . match_type ) ;
348
348
349
349
let ro = Arc :: new ( ro) ;
350
- Ok ( Exec { ro : ro, cache : CachedThreadLocal :: new ( ) } )
350
+ Ok ( Exec { ro : ro, cache : Cached :: new ( ) } )
351
351
}
352
352
}
353
353
@@ -423,7 +423,7 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
423
423
MatchType :: DfaAnchoredReverse => {
424
424
match dfa:: Fsm :: reverse (
425
425
& self . ro . dfa_reverse ,
426
- self . cache ,
426
+ self . cache . value ( ) ,
427
427
true ,
428
428
& text[ start..] ,
429
429
text. len ( ) ,
@@ -471,7 +471,7 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
471
471
MatchType :: DfaAnchoredReverse => {
472
472
match dfa:: Fsm :: reverse (
473
473
& self . ro . dfa_reverse ,
474
- self . cache ,
474
+ self . cache . value ( ) ,
475
475
true ,
476
476
& text[ start..] ,
477
477
text. len ( ) ,
@@ -691,7 +691,7 @@ impl<'c> ExecNoSync<'c> {
691
691
use dfa:: Result :: * ;
692
692
let end = match dfa:: Fsm :: forward (
693
693
& self . ro . dfa ,
694
- self . cache ,
694
+ self . cache . value ( ) ,
695
695
false ,
696
696
text,
697
697
start,
@@ -704,7 +704,7 @@ impl<'c> ExecNoSync<'c> {
704
704
// Now run the DFA in reverse to find the start of the match.
705
705
match dfa:: Fsm :: reverse (
706
706
& self . ro . dfa_reverse ,
707
- self . cache ,
707
+ self . cache . value ( ) ,
708
708
false ,
709
709
& text[ start..] ,
710
710
end - start,
@@ -730,7 +730,7 @@ impl<'c> ExecNoSync<'c> {
730
730
use dfa:: Result :: * ;
731
731
match dfa:: Fsm :: reverse (
732
732
& self . ro . dfa_reverse ,
733
- self . cache ,
733
+ self . cache . value ( ) ,
734
734
false ,
735
735
& text[ start..] ,
736
736
text. len ( ) - start,
@@ -744,7 +744,7 @@ impl<'c> ExecNoSync<'c> {
744
744
/// Finds the end of the shortest match using only the DFA.
745
745
#[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
746
746
fn shortest_dfa ( & self , text : & [ u8 ] , start : usize ) -> dfa:: Result < usize > {
747
- dfa:: Fsm :: forward ( & self . ro . dfa , self . cache , true , text, start)
747
+ dfa:: Fsm :: forward ( & self . ro . dfa , self . cache . value ( ) , true , text, start)
748
748
}
749
749
750
750
/// Finds the end of the shortest match using only the DFA by scanning for
@@ -796,7 +796,7 @@ impl<'c> ExecNoSync<'c> {
796
796
end = last_literal + lcs. len ( ) ;
797
797
match dfa:: Fsm :: reverse (
798
798
& self . ro . dfa_reverse ,
799
- self . cache ,
799
+ self . cache . value ( ) ,
800
800
false ,
801
801
& text[ start..end] ,
802
802
end - start,
@@ -841,7 +841,7 @@ impl<'c> ExecNoSync<'c> {
841
841
// leftmost-first match.)
842
842
match dfa:: Fsm :: forward (
843
843
& self . ro . dfa ,
844
- self . cache ,
844
+ self . cache . value ( ) ,
845
845
false ,
846
846
text,
847
847
match_start,
@@ -1007,7 +1007,7 @@ impl<'c> ExecNoSync<'c> {
1007
1007
if self . ro . nfa . uses_bytes ( ) {
1008
1008
pikevm:: Fsm :: exec (
1009
1009
& self . ro . nfa ,
1010
- self . cache ,
1010
+ self . cache . value ( ) ,
1011
1011
matches,
1012
1012
slots,
1013
1013
quit_after_match,
@@ -1018,7 +1018,7 @@ impl<'c> ExecNoSync<'c> {
1018
1018
} else {
1019
1019
pikevm:: Fsm :: exec (
1020
1020
& self . ro . nfa ,
1021
- self . cache ,
1021
+ self . cache . value ( ) ,
1022
1022
matches,
1023
1023
slots,
1024
1024
quit_after_match,
@@ -1041,7 +1041,7 @@ impl<'c> ExecNoSync<'c> {
1041
1041
if self . ro . nfa . uses_bytes ( ) {
1042
1042
backtrack:: Bounded :: exec (
1043
1043
& self . ro . nfa ,
1044
- self . cache ,
1044
+ self . cache . value ( ) ,
1045
1045
matches,
1046
1046
slots,
1047
1047
ByteInput :: new ( text, self . ro . nfa . only_utf8 ) ,
@@ -1051,7 +1051,7 @@ impl<'c> ExecNoSync<'c> {
1051
1051
} else {
1052
1052
backtrack:: Bounded :: exec (
1053
1053
& self . ro . nfa ,
1054
- self . cache ,
1054
+ self . cache . value ( ) ,
1055
1055
matches,
1056
1056
slots,
1057
1057
CharInput :: new ( text) ,
@@ -1087,7 +1087,7 @@ impl<'c> ExecNoSync<'c> {
1087
1087
Dfa | DfaAnchoredReverse | DfaSuffix | DfaMany => {
1088
1088
match dfa:: Fsm :: forward_many (
1089
1089
& self . ro . dfa ,
1090
- self . cache ,
1090
+ self . cache . value ( ) ,
1091
1091
matches,
1092
1092
text,
1093
1093
start,
@@ -1145,8 +1145,7 @@ impl Exec {
1145
1145
/// Get a searcher that isn't Sync.
1146
1146
#[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
1147
1147
pub fn searcher ( & self ) -> ExecNoSync {
1148
- let create =
1149
- || Box :: new ( RefCell :: new ( ProgramCacheInner :: new ( & self . ro ) ) ) ;
1148
+ let create = || RefCell :: new ( ProgramCacheInner :: new ( & self . ro ) ) ;
1150
1149
ExecNoSync {
1151
1150
ro : & self . ro , // a clone is too expensive here! (and not needed)
1152
1151
cache : self . cache . get_or ( create) ,
@@ -1201,7 +1200,7 @@ impl Exec {
1201
1200
1202
1201
impl Clone for Exec {
1203
1202
fn clone ( & self ) -> Exec {
1204
- Exec { ro : self . ro . clone ( ) , cache : CachedThreadLocal :: new ( ) }
1203
+ Exec { ro : self . ro . clone ( ) , cache : Cached :: new ( ) }
1205
1204
}
1206
1205
}
1207
1206
0 commit comments