mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-12 06:17:16 +00:00
Avoid allocating in nice_directory_display
when possible
This commit is contained in:
parent
2af0464ed3
commit
75ece05dbf
11
src/utils.rs
11
src/utils.rs
@ -1,6 +1,7 @@
|
|||||||
//! Random stuff used on ouch.
|
//! Random stuff used on ouch.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
cmp, env,
|
cmp, env,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
io,
|
io,
|
||||||
@ -109,12 +110,12 @@ pub fn concatenate_list_of_os_str(os_strs: &[impl AsRef<OsStr>]) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Display the directory name, but change to "current directory" when necessary.
|
/// Display the directory name, but change to "current directory" when necessary.
|
||||||
pub fn nice_directory_display(os_str: impl AsRef<OsStr>) -> String {
|
pub fn nice_directory_display(os_str: impl AsRef<OsStr>) -> Cow<'static, str> {
|
||||||
let text = to_utf(os_str);
|
if os_str.as_ref() == "." {
|
||||||
if text == "." {
|
Cow::Borrowed("current directory")
|
||||||
"current directory".to_string()
|
|
||||||
} else {
|
} else {
|
||||||
format!("'{}'", text)
|
let text = to_utf(os_str);
|
||||||
|
Cow::Owned(format!("'{}'", text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user