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 Oxide Scanner calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  43de58ea_7c3b_c3a8_09fb_485a31ec14d6["optimize_patterns()"]
  06f0538c_a174_ca7e_0254_932670828484["glob.rs"]
  43de58ea_7c3b_c3a8_09fb_485a31ec14d6 -->|defined in| 06f0538c_a174_ca7e_0254_932670828484
  3b14a9e7_5d43_bc68_e82b_f61c14c46ab9["test()"]
  3b14a9e7_5d43_bc68_e82b_f61c14c46ab9 -->|calls| 43de58ea_7c3b_c3a8_09fb_485a31ec14d6
  ddde4a02_2208_94ac_5add_f38889ce914b["hoist_static_glob_parts()"]
  43de58ea_7c3b_c3a8_09fb_485a31ec14d6 -->|calls| ddde4a02_2208_94ac_5add_f38889ce914b
  style 43de58ea_7c3b_c3a8_09fb_485a31ec14d6 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, 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