From d0ff59cfe538203667e93703af495719c1f2ea3f Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 7 Jan 2026 17:22:35 +0100 Subject: [PATCH] [ty] Use `Pool` from `regex_automata` to reuse the `matches` allocations (#22438) --- crates/ty_project/src/glob/exclude.rs | 6 +++--- crates/ty_project/src/glob/include.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/ty_project/src/glob/exclude.rs b/crates/ty_project/src/glob/exclude.rs index ab657c0c76..3f279ad051 100644 --- a/crates/ty_project/src/glob/exclude.rs +++ b/crates/ty_project/src/glob/exclude.rs @@ -124,7 +124,7 @@ struct Gitignore { set: GlobSet, globs: Vec, #[get_size(ignore)] - matches: Option>>>, + matches: Arc>>, } impl Gitignore { @@ -140,7 +140,7 @@ impl Gitignore { return Match::None; } - let mut matches = self.matches.as_ref().unwrap().get(); + let mut matches = self.matches.get(); let candidate = Candidate::new(path); self.set.matches_candidate_into(&candidate, &mut matches); for &i in matches.iter().rev() { @@ -232,7 +232,7 @@ impl GitignoreBuilder { Ok(Gitignore { set, globs: self.globs.clone(), - matches: Some(Arc::new(Pool::new(Vec::new))), + matches: Arc::new(Pool::new(Vec::new)), }) } diff --git a/crates/ty_project/src/glob/include.rs b/crates/ty_project/src/glob/include.rs index c828f9f128..73c1863168 100644 --- a/crates/ty_project/src/glob/include.rs +++ b/crates/ty_project/src/glob/include.rs @@ -1,9 +1,11 @@ use globset::{Glob, GlobBuilder, GlobSet, GlobSetBuilder}; use regex_automata::dfa; use regex_automata::dfa::Automaton; +use regex_automata::util::pool::Pool; use ruff_db::system::SystemPath; use std::fmt::Formatter; use std::path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}; +use std::sync::Arc; use tracing::warn; use crate::glob::portable::AbsolutePortableGlobPattern; @@ -37,6 +39,8 @@ pub(crate) struct IncludeFilter { literal_pattern_indices: Box<[usize]>, #[get_size(size_fn = dfa_memory_usage)] dfa: Option>>, + #[get_size(ignore)] + matches: Arc>>, } #[allow(clippy::ref_option)] @@ -57,13 +61,14 @@ impl IncludeFilter { }; } - let matches = self.glob_set.matches(path); + let mut matches = self.matches.get(); + self.glob_set.matches_into(path, &mut matches); if matches.is_empty() { MatchFile::No } else { - for match_index in matches { - if self.literal_pattern_indices.contains(&match_index) { + for match_index in matches.iter() { + if self.literal_pattern_indices.contains(match_index) { return MatchFile::Literal; } } @@ -291,6 +296,7 @@ impl IncludeFilterBuilder { dfa, literal_pattern_indices: self.literal_pattern_indices.into(), original_patterns: self.original_patterns.into(), + matches: Arc::new(Pool::new(Vec::new)), }) } }