Home / Function/ optimize_patterns() — tailwindcss Function Reference

optimize_patterns() — tailwindcss Function Reference

Architecture documentation for the optimize_patterns() function in glob.rs from the tailwindcss codebase.

Function rust RustCore FileScanner calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  acf2f0a7_f6d0_3770_148f_551b6caf03fc["optimize_patterns()"]
  259c9079_e6e4_38be_be7c_c860a61e0b2f["test()"]
  259c9079_e6e4_38be_be7c_c860a61e0b2f -->|calls| acf2f0a7_f6d0_3770_148f_551b6caf03fc
  2f10b262_24d5_643d_e262_4238e7d8b5ff["hoist_static_glob_parts()"]
  acf2f0a7_f6d0_3770_148f_551b6caf03fc -->|calls| 2f10b262_24d5_643d_e262_4238e7d8b5ff
  style acf2f0a7_f6d0_3770_148f_551b6caf03fc 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

Called By

Frequently Asked Questions

What does optimize_patterns() do?
optimize_patterns() is a function in the tailwindcss codebase.
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