Skip to content

Commit 68d6344

Browse files
authored
du: Use rustc-hash for du -a - improve performance by 24.89% (#10663)
1 parent 69f11b3 commit 68d6344

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/du/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ uucore = { workspace = true, features = [
2828
"parser-glob",
2929
"time",
3030
] }
31+
rustc-hash = { workspace = true }
3132
thiserror = { workspace = true }
3233
fluent = { workspace = true }
3334

src/uu/du/src/du.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue};
99
use glob::Pattern;
10-
use std::collections::HashSet;
10+
use rustc_hash::FxHashSet as HashSet;
1111
use std::env;
1212
use std::ffi::{OsStr, OsString};
1313
use std::fs::{self, DirEntry, File, Metadata};
@@ -578,7 +578,7 @@ fn du_regular(
578578
ancestors: Option<&mut HashSet<FileInfo>>,
579579
symlink_depth: Option<usize>,
580580
) -> Result<Stat, Box<mpsc::SendError<UResult<StatPrintInfo>>>> {
581-
let mut default_ancestors = HashSet::new();
581+
let mut default_ancestors = HashSet::default();
582582
let ancestors = ancestors.unwrap_or(&mut default_ancestors);
583583
let symlink_depth = symlink_depth.unwrap_or(0);
584584
// Maximum symlink depth to prevent infinite loops
@@ -995,7 +995,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
995995
files.collect()
996996
} else {
997997
// Deduplicate while preserving order
998-
let mut seen = HashSet::new();
998+
let mut seen = HashSet::default();
999999
files
10001000
.filter(|path| seen.insert(path.clone()))
10011001
.collect::<Vec<_>>()
@@ -1088,7 +1088,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
10881088
let printing_thread = thread::spawn(move || stat_printer.print_stats(&rx));
10891089

10901090
// Check existence of path provided in argument
1091-
let mut seen_inodes: HashSet<FileInfo> = HashSet::new();
1091+
let mut seen_inodes: HashSet<FileInfo> = HashSet::default();
10921092

10931093
'loop_file: for path in files {
10941094
// Skip if we don't want to ignore anything

0 commit comments

Comments
 (0)