Skip to content

Commit cb022de

Browse files
committed
Replace mempool with thread_local
1 parent 2ab7be3 commit cb022de

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.3.0
3+
- 1.6.0
44
- stable
55
- beta
66
- nightly

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ aho-corasick = "0.5.1"
1818
# For skipping along search text quickly when a leading byte is known.
1919
memchr = "0.1.9"
2020
# For managing regex caches quickly across multiple threads.
21-
mempool = "0.3.0"
21+
thread_local = "0.2.0"
2222
# For parsing regular expressions.
2323
regex-syntax = { path = "regex-syntax", version = "0.3.1" }
2424
# For compiling UTF-8 decoding into automata.

src/exec.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::cell::RefCell;
1212
use std::collections::HashMap;
1313
use std::sync::Arc;
1414

15-
use mempool::Pool;
15+
use thread_local::CachedThreadLocal;
1616
use syntax::{Expr, ExprBuilder, Literals};
1717

1818
use 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)]
3736
pub 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

@@ -703,9 +700,10 @@ impl Exec {
703700
/// Get a searcher that isn't Sync.
704701
#[inline(always)] // reduces constant overhead
705702
pub fn searcher(&self) -> ExecNoSync {
703+
let create = || Box::new(RefCell::new(ProgramCacheInner::new(&self.ro)));
706704
ExecNoSync {
707705
ro: &self.ro, // a clone is too expensive here! (and not needed)
708-
cache: self.cache.get(),
706+
cache: self.cache.get_or(create),
709707
}
710708
}
711709

@@ -759,7 +757,7 @@ impl Clone for Exec {
759757
fn clone(&self) -> Exec {
760758
Exec {
761759
ro: self.ro.clone(),
762-
cache: create_pool(self.ro.clone()),
760+
cache: CachedThreadLocal::new(),
763761
}
764762
}
765763
}
@@ -863,11 +861,6 @@ pub struct ProgramCacheInner {
863861
pub dfa_reverse: dfa::Cache,
864862
}
865863

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-
871864
impl ProgramCacheInner {
872865
fn new(ro: &ExecReadOnly) -> Self {
873866
ProgramCacheInner {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@
505505

506506
extern crate aho_corasick;
507507
extern crate memchr;
508-
extern crate mempool;
508+
extern crate thread_local;
509509
#[cfg(test)] extern crate quickcheck;
510510
extern crate regex_syntax as syntax;
511511
extern crate utf8_ranges;

0 commit comments

Comments
 (0)