From 86d3fa92cb32c18bdf323717a575aec69f4c67e1 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 29 Feb 2024 23:25:44 +0100 Subject: [PATCH] Optimize fold_home_dir --- helix-stdx/src/path.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helix-stdx/src/path.rs b/helix-stdx/src/path.rs index 1dc4d0b2448b..42d7a9b602df 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); } }