Skip to content

Commit 40d9da1

Browse files
committed
ls: Use rustc-hash at colors
1 parent 9ac174b commit 40d9da1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

‎src/uu/ls/src/colors.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// file that was distributed with this source code.
55
use super::PathData;
66
use lscolors::{Indicator, LsColors, Style};
7+
use rustc_hash::FxHashMap;
78
use std::borrow::Cow;
8-
use std::collections::HashMap;
99
use std::env;
1010
use std::ffi::OsString;
1111
use std::fs::{self, Metadata};
@@ -45,7 +45,7 @@ pub(crate) struct StyleManager<'a> {
4545
pub(crate) initial_reset_is_done: bool,
4646
pub(crate) colors: &'a LsColors,
4747
/// raw indicator codes as specified in LS_COLORS (if available)
48-
indicator_codes: HashMap<Indicator, String>,
48+
indicator_codes: FxHashMap<Indicator, String>,
4949
/// whether ln=target is active
5050
ln_color_from_target: bool,
5151
}
@@ -746,8 +746,8 @@ fn is_valid_ls_colors_prefix(label: [u8; 2]) -> bool {
746746
)
747747
}
748748

749-
fn parse_indicator_codes() -> (HashMap<Indicator, String>, bool) {
750-
let mut indicator_codes = HashMap::new();
749+
fn parse_indicator_codes() -> (FxHashMap<Indicator, String>, bool) {
750+
let mut indicator_codes = FxHashMap::default();
751751
let mut ln_color_from_target = false;
752752

753753
// LS_COLORS validity is checked before enabling color output, so parse
@@ -813,7 +813,7 @@ mod tests {
813813

814814
fn style_manager(
815815
colors: &LsColors,
816-
indicator_codes: HashMap<Indicator, String>,
816+
indicator_codes: FxHashMap<Indicator, String>,
817817
) -> StyleManager<'_> {
818818
StyleManager {
819819
current_style: None,
@@ -827,21 +827,21 @@ mod tests {
827827
#[test]
828828
fn has_indicator_style_ignores_fallback_styles() {
829829
let colors = LsColors::from_string("ex=00:fi=32");
830-
let manager = style_manager(&colors, HashMap::new());
830+
let manager = style_manager(&colors, FxHashMap::default());
831831
assert!(!manager.has_indicator_style(Indicator::ExecutableFile));
832832
}
833833

834834
#[test]
835835
fn has_indicator_style_detects_explicit_styles() {
836836
let colors = LsColors::from_string("ex=01;32");
837-
let manager = style_manager(&colors, HashMap::new());
837+
let manager = style_manager(&colors, FxHashMap::default());
838838
assert!(manager.has_indicator_style(Indicator::ExecutableFile));
839839
}
840840

841841
#[test]
842842
fn has_indicator_style_detects_raw_codes() {
843843
let colors = LsColors::empty();
844-
let mut indicator_codes = HashMap::new();
844+
let mut indicator_codes = FxHashMap::default();
845845
indicator_codes.insert(Indicator::Directory, "01;34".to_string());
846846
let manager = style_manager(&colors, indicator_codes);
847847
assert!(manager.has_indicator_style(Indicator::Directory));

‎src/uu/ls/src/ls.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,11 +3527,11 @@ fn create_hyperlink(name: &OsStr, path: &PathData) -> OsString {
35273527
// Get bytes for URL encoding in a cross-platform way
35283528
let absolute_path_bytes = os_str_as_bytes_lossy(absolute_path.as_os_str());
35293529

3530-
// Create a set of safe ASCII bytes that don't need encoding
3530+
// a set of safe ASCII bytes that don't need encoding
35313531
#[cfg(not(target_os = "windows"))]
3532-
let unencoded_bytes: std::collections::HashSet<u8> = "_-.~/".bytes().collect();
3532+
let unencoded_bytes = b"_-.~/";
35333533
#[cfg(target_os = "windows")]
3534-
let unencoded_bytes: std::collections::HashSet<u8> = "_-.~/\\:".bytes().collect();
3534+
let unencoded_bytes = b"_-.~/\\:";
35353535

35363536
// Encode at byte level to properly handle UTF-8 sequences and preserve invalid UTF-8
35373537
let full_encoded_path: String = absolute_path_bytes

0 commit comments

Comments
 (0)