Skip to content

Commit 005d1d3

Browse files
committed
refactor: rename DisplayItemName struct and optimize dired_name_len calculation
The commit renames the `DisplayItemName` struct to avoid conflicts and optimizes the `dired_name_len` calculation by only computing it when dired mode is enabled, improving performance for non-dired displays.
1 parent f8462cb commit 005d1d3

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/uu/ls/src/ls.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ struct PaddingCollection {
408408
block_size: usize,
409409
}
410410

411+
struct DisplayItemName {
412+
displayed: OsString,
413+
dired_name_len: usize,
414+
}
415+
411416
/// Extracts the format to display the information based on the options provided.
412417
///
413418
/// # Returns
@@ -3029,7 +3034,7 @@ fn display_item_long(
30293034
display_date(md, config, state, &mut output_display)?;
30303035
output_display.extend(b" ");
30313036

3032-
let item_name = display_item_name(
3037+
let item_display = display_item_name(
30333038
item,
30343039
config,
30353040
None,
@@ -3040,16 +3045,16 @@ fn display_item_long(
30403045
})),
30413046
);
30423047

3043-
let mut dired_name_len = item_name.dired_name_len;
3044-
let name = item_name.displayed;
3045-
let needs_space = quoted && !os_str_starts_with(&name, b"'");
3048+
let mut dired_name_len = item_display.dired_name_len;
3049+
let item_name = item_display.displayed;
3050+
let needs_space = quoted && !os_str_starts_with(&item_name, b"'");
30463051
let displayed_item = if needs_space {
30473052
dired_name_len += 1;
30483053
let mut ret: OsString = " ".into();
3049-
ret.push(name);
3054+
ret.push(&item_name);
30503055
ret
30513056
} else {
3052-
name
3057+
item_name
30533058
};
30543059

30553060
if config.dired {
@@ -3324,11 +3329,6 @@ fn classify_file(path: &PathData) -> Option<char> {
33243329
///
33253330
/// Note that non-unicode sequences in symlink targets are dealt with using
33263331
/// [`std::path::Path::to_string_lossy`].
3327-
struct DisplayItemName {
3328-
displayed: OsString,
3329-
dired_name_len: usize,
3330-
}
3331-
33323332
#[allow(clippy::cognitive_complexity)]
33333333
fn display_item_name(
33343334
path: &PathData,
@@ -3388,7 +3388,7 @@ fn display_item_name(
33883388
}
33893389
}
33903390

3391-
let dired_name_len = name.len();
3391+
let dired_name_len = if config.dired { name.len() } else { 0 };
33923392

33933393
if config.format == Format::Long
33943394
&& path.file_type().is_some_and(|ft| ft.is_symlink())

0 commit comments

Comments
 (0)