diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -18,6 +18,7 @@ use std::sync::{Arc, Mutex}; pub mod ansi; pub mod basedir; +mod bitset; pub mod completion; pub mod consts; pub mod ctrlc; @@ -31,6 +32,7 @@ pub mod panic; pub mod parse; pub mod ps1; pub mod raw; +pub mod regex; pub mod reload; pub mod run; pub mod rw; @@ -38,8 +40,6 @@ pub mod serialization; pub mod syntax_highlighting; pub mod variants; pub mod wait; -pub mod regex; -mod bitset; use raw::*; @@ -49,6 +49,8 @@ use crate::history::HistoryEntry; use crate::line::Line; use crate::parse::{Block, ExpString, Parse, PostExpansion}; use crate::ps1::Prompt; +use crate::regex::bc::RegexCompilationError; +use crate::regex::{CompiledPattern, Pattern, RegexEngine}; macro_rules! print { ($($x:tt)*) => {{ @@ -123,6 +125,8 @@ pub struct Session { prompt: Prompt, terminal_input: Option<ansi::TerminalInput>, + + regex_cache: HashMap<Pattern, Result<Arc<CompiledPattern>, RegexCompilationError>>, } impl Session { @@ -148,6 +152,7 @@ impl Session { prompt, vars, terminal_input: None, + regex_cache: HashMap::new(), } } } @@ -345,6 +350,24 @@ impl Session { self.line.highlight_syntax(&mut self.highlighter)?; Ok(()) } + + fn cached_regex( + se: &Mutex<Self>, + pat: Pattern, + ) -> Result<Arc<CompiledPattern>, RegexCompilationError> { + let mut this = se.lock().unwrap(); + if let Some(re) = this.regex_cache.get(&pat) { + re.clone() + } else { + let res = CompiledPattern::compile(pat.clone()); + let res = match res { + Ok(re) => Ok(Arc::new(re)), + Err(e) => Err(e), + }; + this.regex_cache.insert(pat, res.clone()); + res + } + } } const DEFAULT_PROFILE: &[u8] = include_bytes!("profile"); |
