@@ -12,7 +12,7 @@ use std::cell::RefCell;
1212use std:: collections:: HashMap ;
1313use std:: sync:: Arc ;
1414
15- use mempool :: Pool ;
15+ use thread_local :: CachedThreadLocal ;
1616use syntax:: { Expr , ExprBuilder , Literals } ;
1717
1818use backtrack;
@@ -33,12 +33,11 @@ use set;
3333/// In particular, this manages the various compiled forms of a single regular
3434/// expression and the choice of which matching engine to use to execute a
3535/// regular expression.
36- #[ derive( Debug ) ]
3736pub struct Exec {
3837 /// All read only state.
3938 ro : Arc < ExecReadOnly > ,
4039 /// Caches for the various matching engines.
41- cache : Pool < ProgramCache > ,
40+ cache : CachedThreadLocal < ProgramCache > ,
4241}
4342
4443/// ExecNoSync is like Exec, except it embeds a reference to a cache. This
@@ -204,8 +203,7 @@ impl ExecBuilder {
204203 suffixes : LiteralSearcher :: empty ( ) ,
205204 match_type : MatchType :: Nothing ,
206205 } ) ;
207- let ro_ = ro. clone ( ) ;
208- return Ok ( Exec { ro : ro, cache : create_pool ( ro_) } ) ;
206+ return Ok ( Exec { ro : ro, cache : CachedThreadLocal :: new ( ) } ) ;
209207 }
210208 let parsed = try!( Parsed :: parse ( & self . res , self . only_utf8 ) ) ;
211209 let mut nfa = try!(
@@ -245,8 +243,7 @@ impl ExecBuilder {
245243 // println!("MATCH TYPE for '{:?}': {:?}", ro.res, ro.match_type);
246244
247245 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 ( ) } )
250247 }
251248}
252249
@@ -767,9 +764,10 @@ impl Exec {
767764 /// Get a searcher that isn't Sync.
768765 #[ inline( always) ] // reduces constant overhead
769766 pub fn searcher ( & self ) -> ExecNoSync {
767+ let create = || Box :: new ( RefCell :: new ( ProgramCacheInner :: new ( & self . ro ) ) ) ;
770768 ExecNoSync {
771769 ro : & self . ro , // a clone is too expensive here! (and not needed)
772- cache : self . cache . get ( ) ,
770+ cache : self . cache . get_or ( create ) ,
773771 }
774772 }
775773
@@ -823,7 +821,7 @@ impl Clone for Exec {
823821 fn clone ( & self ) -> Exec {
824822 Exec {
825823 ro : self . ro . clone ( ) ,
826- cache : create_pool ( self . ro . clone ( ) ) ,
824+ cache : CachedThreadLocal :: new ( ) ,
827825 }
828826 }
829827}
@@ -934,11 +932,6 @@ pub struct ProgramCacheInner {
934932 pub dfa_reverse : dfa:: Cache ,
935933}
936934
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-
942935impl ProgramCacheInner {
943936 fn new ( ro : & ExecReadOnly ) -> Self {
944937 ProgramCacheInner {
0 commit comments