@@ -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
@@ -703,9 +700,10 @@ impl Exec {
703
700
/// Get a searcher that isn't Sync.
704
701
#[ inline( always) ] // reduces constant overhead
705
702
pub fn searcher ( & self ) -> ExecNoSync {
703
+ let create = || Box :: new ( RefCell :: new ( ProgramCacheInner :: new ( & self . ro ) ) ) ;
706
704
ExecNoSync {
707
705
ro : & self . ro , // a clone is too expensive here! (and not needed)
708
- cache : self . cache . get ( ) ,
706
+ cache : self . cache . get_or ( create ) ,
709
707
}
710
708
}
711
709
@@ -759,7 +757,7 @@ impl Clone for Exec {
759
757
fn clone ( & self ) -> Exec {
760
758
Exec {
761
759
ro : self . ro . clone ( ) ,
762
- cache : create_pool ( self . ro . clone ( ) ) ,
760
+ cache : CachedThreadLocal :: new ( ) ,
763
761
}
764
762
}
765
763
}
@@ -863,11 +861,6 @@ pub struct ProgramCacheInner {
863
861
pub dfa_reverse : dfa:: Cache ,
864
862
}
865
863
866
- /// Creates a fresh pool.
867
- fn create_pool ( ro : Arc < ExecReadOnly > ) -> Pool < ProgramCache > {
868
- Pool :: new ( Box :: new ( move || RefCell :: new ( ProgramCacheInner :: new ( & ro) ) ) )
869
- }
870
-
871
864
impl ProgramCacheInner {
872
865
fn new ( ro : & ExecReadOnly ) -> Self {
873
866
ProgramCacheInner {
0 commit comments