diff --git a/Cargo.lock b/Cargo.lock index c6d603349..adfca7577 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4306,6 +4306,7 @@ dependencies = [ "codspeed-divan-compat", "fluent", "nix", + "rustc-hash", "string-interner", "thiserror 2.0.18", "uucore", diff --git a/Cargo.toml b/Cargo.toml index 607b1b198..0346e8f91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -371,6 +371,7 @@ rayon = "1.10" regex = "1.10.4" rlimit = "0.11.0" rstest = "0.26.0" +rustc-hash = "2.1.1" rust-ini = "0.21.0" same-file = "1.0.6" self_cell = "1.0.4" diff --git a/src/uu/shuf/Cargo.toml b/src/uu/shuf/Cargo.toml index cd2c50072..49b1f4e16 100644 --- a/src/uu/shuf/Cargo.toml +++ b/src/uu/shuf/Cargo.toml @@ -26,7 +26,7 @@ rand_core = { workspace = true } sha3 = { workspace = true } uucore = { workspace = true } fluent = { workspace = true } -rustc-hash = "2.1.1" +rustc-hash = { workspace = true } [[bin]] name = "shuf" diff --git a/src/uu/tsort/Cargo.toml b/src/uu/tsort/Cargo.toml index 8819596e0..74209a62f 100644 --- a/src/uu/tsort/Cargo.toml +++ b/src/uu/tsort/Cargo.toml @@ -24,6 +24,7 @@ fluent = { workspace = true } string-interner = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true } +rustc-hash = { workspace = true } [target.'cfg(unix)'.dependencies] nix = { workspace = true, features = ["fs"] } diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 713c2f5c9..6d6fbdfe8 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -5,8 +5,9 @@ //spell-checker:ignore TAOCP indegree fadvise FADV //spell-checker:ignore (libs) interner uclibc use clap::{Arg, ArgAction, Command}; +use rustc_hash::FxHashMap; +use std::collections::VecDeque; use std::collections::hash_map::Entry; -use std::collections::{HashMap, VecDeque}; use std::ffi::OsString; use std::fs::File; use std::io::{self, BufRead, BufReader}; @@ -19,7 +20,7 @@ use uucore::{format_usage, show, translate}; // short types for switching interning behavior on the fly. type Sym = string_interner::symbol::SymbolUsize; -type Interner = StringInterner>; +type Interner = StringInterner, rustc_hash::FxBuildHasher>; mod options { pub const FILE: &str = "file"; @@ -224,18 +225,18 @@ impl Node { struct Graph { name_sym: Sym, - nodes: HashMap, + nodes: FxHashMap, interner: Interner, } impl Graph { fn new(name: String) -> Self { - let mut interner = Interner::new(); + let mut interner = Interner::with_hasher(rustc_hash::FxBuildHasher); let name_sym = interner.get_or_intern(name); Self { name_sym, interner, - nodes: HashMap::default(), + nodes: FxHashMap::default(), } } @@ -357,7 +358,7 @@ impl Graph { let mut nodes: Vec<_> = self.nodes.keys().copied().collect(); nodes.sort_unstable_by(|a, b| self.get_node_name(*a).cmp(self.get_node_name(*b))); - let mut visited = HashMap::new(); + let mut visited = FxHashMap::default(); let mut stack = Vec::with_capacity(self.nodes.len()); for &node in &nodes { if self.dfs(node, &mut visited, &mut stack) { @@ -376,7 +377,7 @@ impl Graph { fn dfs<'a>( &'a self, node: Sym, - visited: &mut HashMap, + visited: &mut FxHashMap, stack: &mut Vec<(Sym, &'a [Sym])>, ) -> bool { stack.push((