optimize_patterns() — tailwindcss Function Reference
Architecture documentation for the optimize_patterns() function in glob.rs from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 77e32ec4_3bad_9b11_3527_863215f783cf["optimize_patterns()"] d6210432_49e5_7bfc_e9c4_6cebc740bb16["glob.rs"] 77e32ec4_3bad_9b11_3527_863215f783cf -->|defined in| d6210432_49e5_7bfc_e9c4_6cebc740bb16 fc119bfa_39ba_8a9d_993d_92d6a3386600["test()"] fc119bfa_39ba_8a9d_993d_92d6a3386600 -->|calls| 77e32ec4_3bad_9b11_3527_863215f783cf 5cbcc657_1c9c_94fa_f9bc_7a654ab63a89["hoist_static_glob_parts()"] 77e32ec4_3bad_9b11_3527_863215f783cf -->|calls| 5cbcc657_1c9c_94fa_f9bc_7a654ab63a89 style 77e32ec4_3bad_9b11_3527_863215f783cf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
crates/oxide/src/glob.rs lines 91–133
pub fn optimize_patterns(entries: &Vec<GlobEntry>) -> Vec<GlobEntry> {
let entries = hoist_static_glob_parts(entries, true);
// Track all base paths and their patterns. Later we will turn them back into `GlobalEntry`s.
let mut pattern_map: FxHashMap<String, FxHashSet<String>> = FxHashMap::default();
for glob_entry in entries {
let entry = pattern_map.entry(glob_entry.base).or_default();
entry.insert(glob_entry.pattern.clone());
}
let mut glob_entries = pattern_map
.into_iter()
.map(|(base, patterns)| {
let size = patterns.len();
let mut patterns = patterns.into_iter();
GlobEntry {
base,
pattern: match size {
// SAFETY: we can unwrap here because we know that the size is 1.
1 => patterns.next().unwrap(),
_ => {
let mut patterns = patterns.collect::<Vec<_>>();
// Sort the patterns to ensure stable results.
patterns.sort();
// TODO: Right now this will generate something like `{**/*.html,**/*.js}`,
// but maybe we want to generate this instead:`**/*.{html,js}`.
format!("{{{}}}", patterns.join(","))
}
},
}
})
.collect::<Vec<GlobEntry>>();
// Sort the entries by base path to ensure we have stable results.
glob_entries.sort_by(|a, z| a.base.cmp(&z.base));
glob_entries
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does optimize_patterns() do?
optimize_patterns() is a function in the tailwindcss codebase, defined in crates/oxide/src/glob.rs.
Where is optimize_patterns() defined?
optimize_patterns() is defined in crates/oxide/src/glob.rs at line 91.
What does optimize_patterns() call?
optimize_patterns() calls 1 function(s): hoist_static_glob_parts.
What calls optimize_patterns()?
optimize_patterns() is called by 1 function(s): test.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free