Skip to content

Commit

Permalink
Revert "Replace mempool with thread_local"
Browse files Browse the repository at this point in the history
This caused regex to require Rust 1.6, which really should require a
semver bump since it will break existing code. For now, we'll stick with
mempool and move to the faster thread_local version on the next semver
bump (hopefully 1.0).

Fixes #206
  • Loading branch information
BurntSushi committed Apr 22, 2016
1 parent b638d7a commit 7c2aa5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.6.0
- 1.3.0
- stable
- beta
- nightly
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ aho-corasick = "0.5.1"
# For skipping along search text quickly when a leading byte is known.
memchr = "0.1.9"
# For managing regex caches quickly across multiple threads.
thread_local = "0.2.0"
mempool = "0.3.0"
# For parsing regular expressions.
regex-syntax = { path = "regex-syntax", version = "0.3.1" }
# For compiling UTF-8 decoding into automata.
Expand Down
21 changes: 14 additions & 7 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::sync::Arc;

use thread_local::CachedThreadLocal;
use mempool::Pool;
use syntax::{Expr, ExprBuilder, Literals};

use backtrack;
Expand All @@ -33,11 +33,12 @@ use set;
/// In particular, this manages the various compiled forms of a single regular
/// expression and the choice of which matching engine to use to execute a
/// regular expression.
#[derive(Debug)]
pub struct Exec {
/// All read only state.
ro: Arc<ExecReadOnly>,
/// Caches for the various matching engines.
cache: CachedThreadLocal<ProgramCache>,
cache: Pool<ProgramCache>,
}

/// ExecNoSync is like Exec, except it embeds a reference to a cache. This
Expand Down Expand Up @@ -203,7 +204,8 @@ impl ExecBuilder {
suffixes: LiteralSearcher::empty(),
match_type: MatchType::Nothing,
});
return Ok(Exec { ro: ro, cache: CachedThreadLocal::new() });
let ro_ = ro.clone();
return Ok(Exec { ro: ro, cache: create_pool(ro_) });
}
let parsed = try!(Parsed::parse(&self.res, self.only_utf8));
let mut nfa = try!(
Expand Down Expand Up @@ -243,7 +245,8 @@ impl ExecBuilder {
// println!("MATCH TYPE for '{:?}': {:?}", ro.res, ro.match_type);

let ro = Arc::new(ro);
Ok(Exec { ro: ro, cache: CachedThreadLocal::new() })
let ro_ = ro.clone();
Ok(Exec { ro: ro, cache: create_pool(ro_) })
}
}

Expand Down Expand Up @@ -764,10 +767,9 @@ impl Exec {
/// Get a searcher that isn't Sync.
#[inline(always)] // reduces constant overhead
pub fn searcher(&self) -> ExecNoSync {
let create = || Box::new(RefCell::new(ProgramCacheInner::new(&self.ro)));
ExecNoSync {
ro: &self.ro, // a clone is too expensive here! (and not needed)
cache: self.cache.get_or(create),
cache: self.cache.get(),
}
}

Expand Down Expand Up @@ -821,7 +823,7 @@ impl Clone for Exec {
fn clone(&self) -> Exec {
Exec {
ro: self.ro.clone(),
cache: CachedThreadLocal::new(),
cache: create_pool(self.ro.clone()),
}
}
}
Expand Down Expand Up @@ -932,6 +934,11 @@ pub struct ProgramCacheInner {
pub dfa_reverse: dfa::Cache,
}

/// Creates a fresh pool.
fn create_pool(ro: Arc<ExecReadOnly>) -> Pool<ProgramCache> {
Pool::new(Box::new(move || RefCell::new(ProgramCacheInner::new(&ro))))
}

impl ProgramCacheInner {
fn new(ro: &ExecReadOnly) -> Self {
ProgramCacheInner {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@

extern crate aho_corasick;
extern crate memchr;
extern crate thread_local;
extern crate mempool;
#[cfg(test)] extern crate quickcheck;
extern crate regex_syntax as syntax;
extern crate utf8_ranges;
Expand Down

0 comments on commit 7c2aa5c

Please sign in to comment.