mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
tsort: Use rustc-hash - improve performance by 16.74% (#10680)
This commit is contained in:
Generated
+1
@@ -4306,6 +4306,7 @@ dependencies = [
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"nix",
|
||||
"rustc-hash",
|
||||
"string-interner",
|
||||
"thiserror 2.0.18",
|
||||
"uucore",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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<BucketBackend<Sym>>;
|
||||
type Interner = StringInterner<BucketBackend<Sym>, rustc_hash::FxBuildHasher>;
|
||||
|
||||
mod options {
|
||||
pub const FILE: &str = "file";
|
||||
@@ -224,18 +225,18 @@ impl Node {
|
||||
|
||||
struct Graph {
|
||||
name_sym: Sym,
|
||||
nodes: HashMap<Sym, Node>,
|
||||
nodes: FxHashMap<Sym, Node>,
|
||||
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<Sym, VisitedState>,
|
||||
visited: &mut FxHashMap<Sym, VisitedState>,
|
||||
stack: &mut Vec<(Sym, &'a [Sym])>,
|
||||
) -> bool {
|
||||
stack.push((
|
||||
|
||||
Reference in New Issue
Block a user