aboutsummaryrefslogtreecommitdiff
path: root/helix-stdx
diff options
context:
space:
mode:
authormo8it2024-02-29 22:25:44 +0000
committerBlaž Hrastnik2024-03-19 05:39:46 +0000
commit6ed93b6e49df2499cd32cc4e4f6dcfe6d416c907 (patch)
tree3713708b22c6df6112f9ba4769126c01dece10bb /helix-stdx
parent6607938bf82771aff883b45859f614624eadb0d7 (diff)
Optimize fold_home_dir
Diffstat (limited to 'helix-stdx')
-rw-r--r--helix-stdx/src/path.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/helix-stdx/src/path.rs b/helix-stdx/src/path.rs
index 1dc4d0b2..42d7a9b6 100644
--- a/helix-stdx/src/path.rs
+++ b/helix-stdx/src/path.rs
@@ -2,6 +2,7 @@ pub use etcetera::home_dir;
use std::{
borrow::Cow,
+ ffi::OsString,
path::{Component, Path, PathBuf},
};
@@ -12,7 +13,10 @@ use crate::env::current_working_dir;
pub fn fold_home_dir(path: &Path) -> PathBuf {
if let Ok(home) = home_dir() {
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);
}
}