From ed00cec507cd5ac6f6fe55ad7e3f769313e96875 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:08:41 +0900 Subject: [PATCH] mv: Use rustc-hash --- Cargo.lock | 15 +++++++++------ Cargo.toml | 1 + fuzz/Cargo.lock | 1 + src/uu/mv/Cargo.toml | 1 + src/uu/mv/src/hardlink.rs | 6 +++--- src/uu/mv/src/mv.rs | 9 +++++---- src/uucore/Cargo.toml | 1 + src/uucore/src/lib/features/fsxattr.rs | 10 +++++----- tests/by-util/test_mkdir.rs | 5 +++-- 9 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 478e55e0b08..d3cd57f9034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -562,6 +562,7 @@ dependencies = [ "regex", "rlimit", "rstest", + "rustc-hash", "selinux", "sha1", "tempfile", @@ -984,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1685,7 +1686,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1982,7 +1983,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2572,7 +2573,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2872,7 +2873,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3726,6 +3727,7 @@ dependencies = [ "fs_extra", "indicatif", "libc", + "rustc-hash", "tempfile", "thiserror 2.0.18", "uucore", @@ -4414,6 +4416,7 @@ dependencies = [ "num-traits", "os_display", "procfs", + "rustc-hash", "selinux", "sha1", "sha2", @@ -4600,7 +4603,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1aa3892798e..84fe0989282 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -559,6 +559,7 @@ num-prime.workspace = true pretty_assertions = "1.4.0" rand.workspace = true regex.workspace = true +rustc-hash.workspace = true sha1 = { workspace = true, features = ["std"] } tempfile.workspace = true time = { workspace = true, features = ["local-offset"] } diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 520fd775028..a680a252750 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1960,6 +1960,7 @@ dependencies = [ "num-traits", "os_display", "procfs", + "rustc-hash", "sha1", "sha2", "sha3", diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index 5cba2d472ae..88199c80470 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -23,6 +23,7 @@ clap = { workspace = true } fs_extra = { workspace = true } indicatif = { workspace = true } libc = { workspace = true } +rustc-hash = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = [ "backup-control", diff --git a/src/uu/mv/src/hardlink.rs b/src/uu/mv/src/hardlink.rs index 775d3b3c490..8ef687e3562 100644 --- a/src/uu/mv/src/hardlink.rs +++ b/src/uu/mv/src/hardlink.rs @@ -9,7 +9,7 @@ //! This module provides functionality to preserve hardlink relationships //! when moving files across different filesystems/partitions. -use std::collections::HashMap; +use rustc_hash::FxHashMap; use std::io; use std::path::{Path, PathBuf}; @@ -19,14 +19,14 @@ use uucore::display::Quotable; #[derive(Debug, Default)] pub struct HardlinkTracker { /// Maps (device, inode) -> destination path for the first occurrence - inode_map: HashMap<(u64, u64), PathBuf>, + inode_map: FxHashMap<(u64, u64), PathBuf>, } /// Pre-scans files to identify hardlink groups with optimized memory usage #[derive(Debug, Default)] pub struct HardlinkGroupScanner { /// Maps (device, inode) -> list of source paths that are hardlinked together - hardlink_groups: HashMap<(u64, u64), Vec>, + hardlink_groups: FxHashMap<(u64, u64), Vec>, /// List of source files/directories being moved (for destination mapping) source_files: Vec, /// Whether scanning has been performed diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 42e1a9f127e..740f6fbf1e7 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -15,8 +15,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] -use std::collections::HashMap; -use std::collections::HashSet; +use rustc_hash::FxHashMap; +use rustc_hash::FxHashSet; use std::env; use std::ffi::OsString; use std::fs; @@ -575,7 +575,8 @@ pub fn mv(files: &[OsString], opts: &Options) -> UResult<()> { #[allow(clippy::cognitive_complexity)] fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) -> UResult<()> { // remember the moved destinations for further usage - let mut moved_destinations: HashSet = HashSet::with_capacity(files.len()); + let mut moved_destinations: FxHashSet = + FxHashSet::with_capacity_and_hasher(files.len(), rustc_hash::FxBuildHasher); // Create hardlink tracking context #[cfg(unix)] let (mut hardlink_tracker, hardlink_scanner) = { @@ -967,7 +968,7 @@ fn rename_dir_fallback( }; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] - let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| HashMap::new()); + let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| FxHashMap::default()); // Use directory copying (with or without hardlink support) let result = copy_dir_contents( diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 29a7189d444..187634d36b9 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -36,6 +36,7 @@ jiff = { workspace = true, optional = true, features = [ "tzdb-zoneinfo", "tzdb-concatenated", ] } +rustc-hash = { workspace = true } time = { workspace = true, optional = true, features = [ "formatting", "local-offset", diff --git a/src/uucore/src/lib/features/fsxattr.rs b/src/uucore/src/lib/features/fsxattr.rs index 95e7530eeef..d9683264652 100644 --- a/src/uucore/src/lib/features/fsxattr.rs +++ b/src/uucore/src/lib/features/fsxattr.rs @@ -7,7 +7,7 @@ //! Set of functions to manage xattr on files and dirs use itertools::Itertools; -use std::collections::HashMap; +use rustc_hash::FxHashMap; use std::ffi::{OsStr, OsString}; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; @@ -54,8 +54,8 @@ pub fn copy_xattrs_skip_selinux>(source: P, dest: P) -> std::io:: /// # Returns /// /// A result containing a HashMap of attributes names and values, or an error. -pub fn retrieve_xattrs>(source: P) -> std::io::Result>> { - let mut attrs = HashMap::new(); +pub fn retrieve_xattrs>(source: P) -> std::io::Result>> { + let mut attrs = FxHashMap::default(); for attr_name in xattr::list(&source)? { if let Some(value) = xattr::get(&source, &attr_name)? { attrs.insert(attr_name, value); @@ -76,7 +76,7 @@ pub fn retrieve_xattrs>(source: P) -> std::io::Result>( dest: P, - xattrs: HashMap>, + xattrs: FxHashMap>, ) -> std::io::Result<()> { for (attr, value) in xattrs { xattr::set(&dest, &attr, &value)?; @@ -207,7 +207,7 @@ mod tests { File::create(&file_path).unwrap(); - let mut test_xattrs = HashMap::new(); + let mut test_xattrs = FxHashMap::default(); let test_attr = "user.test_attr"; let test_value = b"test value"; test_xattrs.insert(OsString::from(test_attr), test_value.to_vec()); diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 231fe3495d3..9cd164b7411 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -310,13 +310,14 @@ fn test_recursive_reporting() { // TODO Enable and modify this for freebsd when xattr processing for freebsd is enabled. #[cfg(target_os = "linux")] fn test_mkdir_acl() { - use std::{collections::HashMap, ffi::OsString}; + use rustc_hash::FxHashMap; + use std::ffi::OsString; let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("a"); - let mut map: HashMap> = HashMap::new(); + let mut map: FxHashMap> = FxHashMap::default(); // posix_acl entries are in the form of // struct posix_acl_entry{ // tag: u16,