mirror of
https://github.com/nushell/nushell
synced 2024-11-10 23:24:14 +00:00
opt: improve ls by call get_file_type only one time (#5500)
* opt: improve ls by call get_file_type only one time * fmt * cs
This commit is contained in:
parent
7e5e9c28dd
commit
b00098ccc6
1 changed files with 5 additions and 8 deletions
|
@ -353,6 +353,7 @@ pub(crate) fn dir_entry_dict(
|
|||
) -> Result<Value, ShellError> {
|
||||
let mut cols = vec![];
|
||||
let mut vals = vec![];
|
||||
let mut file_type = "unknown";
|
||||
|
||||
cols.push("name".into());
|
||||
vals.push(Value::String {
|
||||
|
@ -361,9 +362,10 @@ pub(crate) fn dir_entry_dict(
|
|||
});
|
||||
|
||||
if let Some(md) = metadata {
|
||||
file_type = get_file_type(md);
|
||||
cols.push("type".into());
|
||||
vals.push(Value::String {
|
||||
val: get_file_type(md).to_string(),
|
||||
val: file_type.to_string(),
|
||||
span,
|
||||
});
|
||||
} else {
|
||||
|
@ -449,10 +451,8 @@ pub(crate) fn dir_entry_dict(
|
|||
|
||||
cols.push("size".to_string());
|
||||
if let Some(md) = metadata {
|
||||
#[cfg(unix)]
|
||||
let zero_sized = md.file_type().is_socket()
|
||||
|| md.file_type().is_char_device()
|
||||
|| md.file_type().is_block_device();
|
||||
let zero_sized =
|
||||
file_type == "socket" || file_type == "block device" || file_type == "char device";
|
||||
|
||||
if md.is_dir() {
|
||||
if du {
|
||||
|
@ -486,9 +486,6 @@ pub(crate) fn dir_entry_dict(
|
|||
vals.push(Value::nothing(span));
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(unix))]
|
||||
let value = Value::nothing(span);
|
||||
#[cfg(unix)]
|
||||
let value = if zero_sized {
|
||||
Value::Filesize { val: 0, span }
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue