ls: Use rustc-hash at colors (#10700)

This commit is contained in:
oech3
2026-03-07 09:56:04 +01:00
committed by GitHub
parent 06ac362484
commit b47076eade
2 changed files with 11 additions and 11 deletions
+8 -8
View File
@@ -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, String>,
indicator_codes: FxHashMap<Indicator, String>,
/// 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<Indicator, String>, bool) {
let mut indicator_codes = HashMap::new();
fn parse_indicator_codes() -> (FxHashMap<Indicator, String>, 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, String>,
indicator_codes: FxHashMap<Indicator, String>,
) -> 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));
+3 -3
View File
@@ -3524,11 +3524,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<u8> = "_-.~/".bytes().collect();
let unencoded_bytes = b"_-.~/";
#[cfg(target_os = "windows")]
let unencoded_bytes: std::collections::HashSet<u8> = "_-.~/\\:".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