From 40d9da15ebb1a3fed7443aadbde2b3d578387446 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:35:36 +0900 Subject: [PATCH] ls: Use rustc-hash at colors --- src/uu/ls/src/colors.rs | 16 ++++++++-------- src/uu/ls/src/ls.rs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs index 958b3c62581..197fd2c8cec 100644 --- a/src/uu/ls/src/colors.rs +++ b/src/uu/ls/src/colors.rs @@ -4,8 +4,8 @@ // file that was distributed with this source code. use super::PathData; use lscolors::{Indicator, LsColors, Style}; +use rustc_hash::FxHashMap; use std::borrow::Cow; -use std::collections::HashMap; use std::env; use std::ffi::OsString; use std::fs::{self, Metadata}; @@ -45,7 +45,7 @@ pub(crate) struct StyleManager<'a> { pub(crate) initial_reset_is_done: bool, pub(crate) colors: &'a LsColors, /// raw indicator codes as specified in LS_COLORS (if available) - indicator_codes: HashMap, + indicator_codes: FxHashMap, /// whether ln=target is active ln_color_from_target: bool, } @@ -746,8 +746,8 @@ fn is_valid_ls_colors_prefix(label: [u8; 2]) -> bool { ) } -fn parse_indicator_codes() -> (HashMap, bool) { - let mut indicator_codes = HashMap::new(); +fn parse_indicator_codes() -> (FxHashMap, bool) { + let mut indicator_codes = FxHashMap::default(); let mut ln_color_from_target = false; // LS_COLORS validity is checked before enabling color output, so parse @@ -813,7 +813,7 @@ mod tests { fn style_manager( colors: &LsColors, - indicator_codes: HashMap, + indicator_codes: FxHashMap, ) -> StyleManager<'_> { StyleManager { current_style: None, @@ -827,21 +827,21 @@ mod tests { #[test] fn has_indicator_style_ignores_fallback_styles() { let colors = LsColors::from_string("ex=00:fi=32"); - let manager = style_manager(&colors, HashMap::new()); + let manager = style_manager(&colors, FxHashMap::default()); assert!(!manager.has_indicator_style(Indicator::ExecutableFile)); } #[test] fn has_indicator_style_detects_explicit_styles() { let colors = LsColors::from_string("ex=01;32"); - let manager = style_manager(&colors, HashMap::new()); + let manager = style_manager(&colors, FxHashMap::default()); assert!(manager.has_indicator_style(Indicator::ExecutableFile)); } #[test] fn has_indicator_style_detects_raw_codes() { let colors = LsColors::empty(); - let mut indicator_codes = HashMap::new(); + let mut indicator_codes = FxHashMap::default(); indicator_codes.insert(Indicator::Directory, "01;34".to_string()); let manager = style_manager(&colors, indicator_codes); assert!(manager.has_indicator_style(Indicator::Directory)); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index afbd8f307a1..1a1a1b0e042 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -3527,11 +3527,11 @@ fn create_hyperlink(name: &OsStr, path: &PathData) -> OsString { // Get bytes for URL encoding in a cross-platform way let absolute_path_bytes = os_str_as_bytes_lossy(absolute_path.as_os_str()); - // Create a set of safe ASCII bytes that don't need encoding + // a set of safe ASCII bytes that don't need encoding #[cfg(not(target_os = "windows"))] - let unencoded_bytes: std::collections::HashSet = "_-.~/".bytes().collect(); + let unencoded_bytes = b"_-.~/"; #[cfg(target_os = "windows")] - let unencoded_bytes: std::collections::HashSet = "_-.~/\\:".bytes().collect(); + let unencoded_bytes = b"_-.~/\\:"; // Encode at byte level to properly handle UTF-8 sequences and preserve invalid UTF-8 let full_encoded_path: String = absolute_path_bytes