From 7c2aa5c660242e196702a6310e74dd00fd3b2040 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 22 Apr 2016 06:43:10 -0400 Subject: [PATCH] Revert "Replace mempool with thread_local" 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 --- .travis.yml | 2 +- Cargo.toml | 2 +- src/exec.rs | 21 ++++++++++++++------- src/lib.rs | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index db5dd3dd8b..0a110a9452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.6.0 + - 1.3.0 - stable - beta - nightly diff --git a/Cargo.toml b/Cargo.toml index 247e4da048..96c3b9d577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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. diff --git a/src/exec.rs b/src/exec.rs index 37db773eb9..adbcbe325d 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -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; @@ -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, /// Caches for the various matching engines. - cache: CachedThreadLocal, + cache: Pool, } /// ExecNoSync is like Exec, except it embeds a reference to a cache. This @@ -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!( @@ -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_) }) } } @@ -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(), } } @@ -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()), } } } @@ -932,6 +934,11 @@ pub struct ProgramCacheInner { pub dfa_reverse: dfa::Cache, } +/// Creates a fresh pool. +fn create_pool(ro: Arc) -> Pool { + Pool::new(Box::new(move || RefCell::new(ProgramCacheInner::new(&ro)))) +} + impl ProgramCacheInner { fn new(ro: &ExecReadOnly) -> Self { ProgramCacheInner { diff --git a/src/lib.rs b/src/lib.rs index 7283edb494..30eb40025c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;