From 524cb209fffc8fd97a6651a26a8eedceb8e8d82c Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Tue, 20 Oct 2026 11:38:19 +0100 Subject: [PATCH] Set regex pool_capacity --- engine/src/ast/parse.rs | 25 +++++++++++++++++++++---- engine/src/rhs_types/regex/imp_real.rs | 8 ++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/engine/src/ast/parse.rs b/engine/src/ast/parse.rs index a9b79ffc..d73b572a 100644 --- a/engine/src/ast/parse.rs +++ b/engine/src/ast/parse.rs @@ -97,12 +97,15 @@ impl Display for ParseError<'_> { /// Parser settings. #[derive(Clone, Debug, PartialEq, Eq)] pub struct ParserSettings { - /// Approximate size of the cache used by the DFA of a regex. - /// Default: 10MB - pub regex_dfa_size_limit: usize, /// Approximate size limit of the compiled regular expression. - /// Default: 2MB + /// Default: 10MB pub regex_compiled_size_limit: usize, + /// Approximate size of the cache used by the DFA of a regex. + /// Default: 2MB + pub regex_dfa_size_limit: usize, + /// Capacity of the managed Cache pool. + /// Default: 8 + pub regex_pool_capacity: usize, /// Maximum number of star metacharacters allowed in a wildcard. /// Default: unlimited pub wildcard_star_limit: usize, @@ -119,6 +122,8 @@ impl Default for ParserSettings { regex_compiled_size_limit: 10 * (1 << 20), // Default value extracted from the regex crate. regex_dfa_size_limit: 2 * (1 << 20), + // Default value extracted from the regex crate. + regex_pool_capacity: 8, wildcard_star_limit: usize::MAX, max_nesting_depth: 128, } @@ -227,6 +232,18 @@ impl<'s> FilterParser<'s> { self.settings.regex_dfa_size_limit } + /// Set capacity of the managed Cache pool. + #[inline] + pub fn regex_set_pool_capacity(&mut self, pool_capacity: usize) { + self.settings.regex_pool_capacity = pool_capacity; + } + + /// Get capacity of the managed Cache pool. + #[inline] + pub fn regex_get_pool_capacity(&self) -> usize { + self.settings.regex_pool_capacity + } + /// Set the maximum number of star metacharacters allowed in a wildcard. #[inline] pub fn wildcard_set_star_limit(&mut self, wildcard_star_limit: usize) { diff --git a/engine/src/rhs_types/regex/imp_real.rs b/engine/src/rhs_types/regex/imp_real.rs index 637539bc..ec821ad8 100644 --- a/engine/src/rhs_types/regex/imp_real.rs +++ b/engine/src/rhs_types/regex/imp_real.rs @@ -15,7 +15,7 @@ pub struct Regex { impl Regex { /// Retrieves the syntax configuration that will be used to build the regex. #[inline] - fn syntax_config() -> regex_automata::util::syntax::Config { + pub fn syntax_config() -> regex_automata::util::syntax::Config { regex_automata::util::syntax::Config::new() .unicode(false) .utf8(false) @@ -23,15 +23,15 @@ impl Regex { /// Retrieves the meta configuration that will be used to build the regex. #[inline] - fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config { + pub fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config { regex_automata::meta::Config::new() .match_kind(MatchKind::LeftmostFirst) .utf8_empty(false) .dfa(false) - .nfa_size_limit(Some(settings.regex_compiled_size_limit)) .onepass(false) - .dfa_size_limit(Some(settings.regex_compiled_size_limit)) + .nfa_size_limit(Some(settings.regex_compiled_size_limit)) .hybrid_cache_capacity(settings.regex_dfa_size_limit) + .pool_capacity(settings.regex_pool_capacity) .which_captures(WhichCaptures::None) }