From 1c38677db0da6f01d1ed04c553b4ea316ed9326a Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sat, 3 Aug 2024 12:27:05 -0700 Subject: [PATCH] Minor cleanup of path_normalize_for_cd --- src/wutil/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 0342f052a..8f52ddf24 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -330,15 +330,14 @@ pub fn path_normalize_for_cd(wd: &wstr, path: &wstr) -> WString { let mut paths = wd_comps; paths.extend(path_comps); let mut result = - WString::with_capacity(paths.iter().fold(0, |sum, s| sum + s.len()) + paths.len() + 1); - result.push(SEP); - // TODO: intersperse() https://github.com/rust-lang/rust/issues/79524 - for (i, p) in paths.iter().enumerate() { - if i != 0 { - result.push(SEP); - } + WString::with_capacity(paths.iter().fold(paths.len() + 1, |sum, s| sum + s.len())); + for p in paths.iter() { + result.push(SEP); result.push_utfstr(*p); } + if result.is_empty() { + result.push(SEP); + } result }