Skip to content

Commit

Permalink
Actually use conditional compilation for matching-cache feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Mar 9, 2024
1 parent 59314b8 commit 6fba315
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/applier/matching_caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::Path;
pub struct GlobMatchingCache<'a> {
path: &'a Path,
match_options: glob::MatchOptions,
#[cfg_attr(not(feature = "matching-cache"), allow(dead_code))]
cached_matches: Vec<Option<bool>>,
}

Expand All @@ -20,7 +21,8 @@ impl<'a> GlobMatchingCache<'a> {
}

pub fn check_pattern_match(&mut self, glob: &Glob) -> bool {
if cfg!(feature = "matching-cache") {
#[cfg(feature = "matching-cache")]
{
let cached = &mut self.cached_matches[glob.get_unique_id()];
if let Some(cached) = &cached {
*cached
Expand All @@ -29,7 +31,9 @@ impl<'a> GlobMatchingCache<'a> {
*cached = Some(computed);
computed
}
} else {
}
#[cfg(not(feature = "matching-cache"))]
{
glob.matches_path_with(self.path, self.match_options)
}
}
Expand All @@ -48,6 +52,7 @@ impl<'a> GlobMatchingCache<'a> {

pub struct RegexMatchingCache<'a> {
line: &'a str,
#[cfg_attr(not(feature = "matching-cache"), allow(dead_code))]
cached_matches: Vec<Option<bool>>,
}

Expand All @@ -62,7 +67,8 @@ impl<'a> RegexMatchingCache<'a> {
}

pub fn check_pattern_match(&mut self, regex: &Regex) -> bool {
if cfg!(feature = "matching-cache") {
#[cfg(feature = "matching-cache")]
{
let cached = &mut self.cached_matches[regex.get_unique_id() + 1];
if let Some(cached) = &cached {
*cached
Expand All @@ -71,13 +77,16 @@ impl<'a> RegexMatchingCache<'a> {
*cached = Some(computed);
computed
}
} else {
}
#[cfg(not(feature = "matching-cache"))]
{
regex.is_match(self.line)
}
}

pub fn check_ignore_marker_match(&mut self) -> bool {
if cfg!(feature = "matching-cache") {
#[cfg(feature = "matching-cache")]
{
let cached = &mut self.cached_matches[0];
if let Some(cached) = &cached {
*cached
Expand All @@ -86,7 +95,9 @@ impl<'a> RegexMatchingCache<'a> {
*cached = Some(computed);
computed
}
} else {
}
#[cfg(not(feature = "matching-cache"))]
{
self.line.contains(IGNORE_MARKER)
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/ruleset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Glob {
self.unique_id = enumerator.get_id(self.pattern.as_str());
}

#[cfg_attr(not(feature = "matching-cache"), allow(dead_code))]
pub fn get_unique_id(&self) -> usize {
debug_assert!(self.unique_id != usize::MAX, "Glob is not enumerated");
self.unique_id
Expand Down Expand Up @@ -111,6 +112,7 @@ impl Regex {
self.unique_id = enumerator.get_id(self.regex.as_str());
}

#[cfg_attr(not(feature = "matching-cache"), allow(dead_code))]
pub fn get_unique_id(&self) -> usize {
debug_assert!(self.unique_id != usize::MAX, "Regex is not enumerated");
self.unique_id
Expand Down

0 comments on commit 6fba315

Please sign in to comment.