Skip to content

Commit a0b2b3f

Browse files
committed
mv: Use rustc-hash
1 parent 289d701 commit a0b2b3f

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

Cargo.lock

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

src/uu/mv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ workspace = true
1919
path = "src/mv.rs"
2020

2121
[dependencies]
22+
rustc-hash = { workspace = true }
2223
clap = { workspace = true }
2324
fs_extra = { workspace = true }
2425
indicatif = { workspace = true }

src/uu/mv/src/hardlink.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! This module provides functionality to preserve hardlink relationships
1010
//! when moving files across different filesystems/partitions.
1111
12-
use std::collections::HashMap;
12+
use rustc_hash::FxHashMap;
1313
use std::io;
1414
use std::path::{Path, PathBuf};
1515

@@ -19,14 +19,14 @@ use uucore::display::Quotable;
1919
#[derive(Debug, Default)]
2020
pub struct HardlinkTracker {
2121
/// Maps (device, inode) -> destination path for the first occurrence
22-
inode_map: HashMap<(u64, u64), PathBuf>,
22+
inode_map: FxHashMap<(u64, u64), PathBuf>,
2323
}
2424

2525
/// Pre-scans files to identify hardlink groups with optimized memory usage
2626
#[derive(Debug, Default)]
2727
pub struct HardlinkGroupScanner {
2828
/// Maps (device, inode) -> list of source paths that are hardlinked together
29-
hardlink_groups: HashMap<(u64, u64), Vec<PathBuf>>,
29+
hardlink_groups: FxHashMap<(u64, u64), Vec<PathBuf>>,
3030
/// List of source files/directories being moved (for destination mapping)
3131
source_files: Vec<PathBuf>,
3232
/// Whether scanning has been performed

src/uu/mv/src/mv.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
1515
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
1616

1717
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
18-
use std::collections::HashMap;
19-
use std::collections::HashSet;
18+
use rustc_hash::FxHashMap;
19+
use rustc_hash::FxHashSet;
2020
use std::env;
2121
use std::ffi::OsString;
2222
use std::fs;
@@ -575,7 +575,8 @@ pub fn mv(files: &[OsString], opts: &Options) -> UResult<()> {
575575
#[allow(clippy::cognitive_complexity)]
576576
fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) -> UResult<()> {
577577
// remember the moved destinations for further usage
578-
let mut moved_destinations: HashSet<PathBuf> = HashSet::with_capacity(files.len());
578+
let mut moved_destinations: FxHashSet<PathBuf> =
579+
FxHashSet::with_capacity_and_hasher(files.len(), rustc_hash::FxBuildHasher);
579580
// Create hardlink tracking context
580581
#[cfg(unix)]
581582
let (mut hardlink_tracker, hardlink_scanner) = {
@@ -967,7 +968,7 @@ fn rename_dir_fallback(
967968
};
968969

969970
#[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))]
970-
let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| HashMap::new());
971+
let xattrs = fsxattr::retrieve_xattrs(from).unwrap_or_else(|_| FxHashMap::default());
971972

972973
// Use directory copying (with or without hardlink support)
973974
let result = copy_dir_contents(

src/uucore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jiff = { workspace = true, optional = true, features = [
3636
"tzdb-zoneinfo",
3737
"tzdb-concatenated",
3838
] }
39+
rustc-hash = { workspace = true }
3940
time = { workspace = true, optional = true, features = [
4041
"formatting",
4142
"local-offset",

src/uucore/src/lib/features/fsxattr.rs

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

88
//! Set of functions to manage xattr on files and dirs
99
use itertools::Itertools;
10-
use std::collections::HashMap;
10+
use rustc_hash::FxHashMap;
1111
use std::ffi::{OsStr, OsString};
1212
#[cfg(unix)]
1313
use std::os::unix::ffi::OsStrExt;
@@ -54,8 +54,8 @@ pub fn copy_xattrs_skip_selinux<P: AsRef<Path>>(source: P, dest: P) -> std::io::
5454
/// # Returns
5555
///
5656
/// A result containing a HashMap of attributes names and values, or an error.
57-
pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<HashMap<OsString, Vec<u8>>> {
58-
let mut attrs = HashMap::new();
57+
pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<FxHashMap<OsString, Vec<u8>>> {
58+
let mut attrs = FxHashMap::default();
5959
for attr_name in xattr::list(&source)? {
6060
if let Some(value) = xattr::get(&source, &attr_name)? {
6161
attrs.insert(attr_name, value);
@@ -76,7 +76,7 @@ pub fn retrieve_xattrs<P: AsRef<Path>>(source: P) -> std::io::Result<HashMap<OsS
7676
/// A result indicating success or failure.
7777
pub fn apply_xattrs<P: AsRef<Path>>(
7878
dest: P,
79-
xattrs: HashMap<OsString, Vec<u8>>,
79+
xattrs: FxHashMap<OsString, Vec<u8>>,
8080
) -> std::io::Result<()> {
8181
for (attr, value) in xattrs {
8282
xattr::set(&dest, &attr, &value)?;
@@ -207,7 +207,7 @@ mod tests {
207207

208208
File::create(&file_path).unwrap();
209209

210-
let mut test_xattrs = HashMap::new();
210+
let mut test_xattrs = FxHashMap::default();
211211
let test_attr = "user.test_attr";
212212
let test_value = b"test value";
213213
test_xattrs.insert(OsString::from(test_attr), test_value.to_vec());

0 commit comments

Comments
 (0)