Skip to content

Commit

Permalink
Optimize fold_home_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it committed Feb 29, 2024
1 parent 234508e commit 86d3fa9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion helix-stdx/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use etcetera::home_dir;

use std::{
borrow::Cow,
ffi::OsString,
path::{Component, Path, PathBuf},
};

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 86d3fa9

Please sign in to comment.