mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Optimize fold_home_dir
This commit is contained in:
parent
6607938bf8
commit
6ed93b6e49
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
|
ffi::OsString,
|
||||||
path::{Component, Path, PathBuf},
|
path::{Component, Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12,7 +13,10 @@
|
|||||||
pub fn fold_home_dir(path: &Path) -> PathBuf {
|
pub fn fold_home_dir(path: &Path) -> PathBuf {
|
||||||
if let Ok(home) = home_dir() {
|
if let Ok(home) = home_dir() {
|
||||||
if let Ok(stripped) = path.strip_prefix(&home) {
|
if let Ok(stripped) = path.strip_prefix(&home) {
|
||||||
return PathBuf::from("~").join(stripped);
|
let mut path = OsString::with_capacity(2 + stripped.as_os_str().len());
|
||||||
|
path.push("~/");
|
||||||
|
path.push(stripped);
|
||||||
|
return PathBuf::from(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user