@@ -12,7 +12,7 @@ use std::cell::RefCell;
12
12
use std:: collections:: HashMap ;
13
13
use std:: sync:: Arc ;
14
14
15
- use mempool :: Pool ;
15
+ use thread_local :: CachedThreadLocal ;
16
16
use syntax:: { Expr , ExprBuilder , Literals } ;
17
17
18
18
use backtrack;
@@ -33,12 +33,11 @@ use set;
33
33
/// In particular, this manages the various compiled forms of a single regular
34
34
/// expression and the choice of which matching engine to use to execute a
35
35
/// regular expression.
36
- #[ derive( Debug ) ]
37
36
pub struct Exec {
38
37
/// All read only state.
39
38
ro : Arc < ExecReadOnly > ,
40
39
/// Caches for the various matching engines.
41
- cache : Pool < ProgramCache > ,
40
+ cache : CachedThreadLocal < ProgramCache > ,
42
41
}
43
42
44
43
/// ExecNoSync is like Exec, except it embeds a reference to a cache. This
@@ -204,8 +203,7 @@ impl ExecBuilder {
204
203
suffixes : LiteralSearcher :: empty ( ) ,
205
204
match_type : MatchType :: Nothing ,
206
205
} ) ;
207
- let ro_ = ro. clone ( ) ;
208
- return Ok ( Exec { ro : ro, cache : create_pool ( ro_) } ) ;
206
+ return Ok ( Exec { ro : ro, cache : CachedThreadLocal :: new ( ) } ) ;
209
207
}
210
208
let parsed = try!( Parsed :: parse ( & self . res , self . only_utf8 ) ) ;
211
209
let mut nfa = try!(
@@ -245,8 +243,7 @@ impl ExecBuilder {
245
243
// println!("MATCH TYPE for '{:?}': {:?}", ro.res, ro.match_type);
246
244
247
245
let ro = Arc :: new ( ro) ;
248
- let ro_ = ro. clone ( ) ;
249
- Ok ( Exec { ro : ro, cache : create_pool ( ro_) } )
246
+ Ok ( Exec { ro : ro, cache : CachedThreadLocal :: new ( ) } )
250
247
}
251
248
}
252
249
@@ -767,9 +764,10 @@ impl Exec {
767
764
/// Get a searcher that isn't Sync.
768
765
#[ inline( always) ] // reduces constant overhead
769
766
pub fn searcher ( & self ) -> ExecNoSync {
767
+ let create = || Box :: new ( RefCell :: new ( ProgramCacheInner :: new ( & self . ro ) ) ) ;
770
768
ExecNoSync {
771
769
ro : & self . ro , // a clone is too expensive here! (and not needed)
772
- cache : self . cache . get ( ) ,
770
+ cache : self . cache . get_or ( create ) ,
773
771
}
774
772
}
775
773
@@ -823,7 +821,7 @@ impl Clone for Exec {
823
821
fn clone ( & self ) -> Exec {
824
822
Exec {
825
823
ro : self . ro . clone ( ) ,
826
- cache : create_pool ( self . ro . clone ( ) ) ,
824
+ cache : CachedThreadLocal :: new ( ) ,
827
825
}
828
826
}
829
827
}
@@ -934,11 +932,6 @@ pub struct ProgramCacheInner {
934
932
pub dfa_reverse : dfa:: Cache ,
935
933
}
936
934
937
- /// Creates a fresh pool.
938
- fn create_pool ( ro : Arc < ExecReadOnly > ) -> Pool < ProgramCache > {
939
- Pool :: new ( Box :: new ( move || RefCell :: new ( ProgramCacheInner :: new ( & ro) ) ) )
940
- }
941
-
942
935
impl ProgramCacheInner {
943
936
fn new ( ro : & ExecReadOnly ) -> Self {
944
937
ProgramCacheInner {
0 commit comments