diff --git a/src/mango/io/fortest/fromstr.rs b/src/mango/io/fortest/fromstr.rs index 3a39b80c..7c70c0d2 100644 --- a/src/mango/io/fortest/fromstr.rs +++ b/src/mango/io/fortest/fromstr.rs @@ -1,5 +1,5 @@ use mango::io::typ::Reader; -use regex::Regex; +use mango::io::util::REXCACHE; /// Implementation of [Reader] that reads from a pre-provided string. /// Mostly for testing purposes. @@ -23,7 +23,11 @@ impl Reader for StringReader { false } - fn matches(&mut self, pattern: Regex) -> Option { - unimplemented!() // TODO + fn matches(&mut self, subpattern: String) -> Option { + REXCACHE.with(|rl| { + let mut rexlib = rl.borrow_mut(); + // let rex = rexlib.make_or_get(subpattern); + }); + Option::None // TODO } } diff --git a/src/mango/io/mod.rs b/src/mango/io/mod.rs index 6dbbd816..d9a219cf 100644 --- a/src/mango/io/mod.rs +++ b/src/mango/io/mod.rs @@ -1,3 +1,5 @@ pub mod typ; pub mod fortest; + +pub mod util; diff --git a/src/mango/io/typ.rs b/src/mango/io/typ.rs index 00aa6f7a..a50008ce 100644 --- a/src/mango/io/typ.rs +++ b/src/mango/io/typ.rs @@ -6,7 +6,7 @@ pub trait Reader { fn equals(&mut self, text: &str) -> bool; /// Checks whether the code from the current position matches a regex pattern. - fn matches(&mut self, pattern: Regex) -> Option; + fn matches(&mut self, subpattern: String) -> Option; } pub trait Writer { diff --git a/src/mango/io/util.rs b/src/mango/io/util.rs new file mode 100644 index 00000000..e847d602 --- /dev/null +++ b/src/mango/io/util.rs @@ -0,0 +1,20 @@ +use regex::Regex; +use std::cell::RefCell; +use std::collections::HashMap; + +pub struct RegexCache { + cache: HashMap, +} + +impl RegexCache { + // Not public to prevent having more than one instance. + pub fn new() -> Self { + RegexCache { + cache: HashMap::new(), + } + } +} + +thread_local! { + pub static REXCACHE: RefCell = RefCell::new(RegexCache::new()) +}