Skip to content

Commit 2cda56e

Browse files
committed
Merge branch 'thread_local'
2 parents 01f23d2 + cdee1e7 commit 2cda56e

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 14 deletions
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

@@ -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-
942935
impl ProgramCacheInner {
943936
fn new(ro: &ExecReadOnly) -> Self {
944937
ProgramCacheInner {

src/lib.rs

Lines changed: 1 addition & 1 deletion
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)