From 28953ef40f24b03340113c351e5de9cf4667f8c9 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 5 Dec 2024 18:50:31 -0500 Subject: [PATCH] Simplify `change_current_directory` and remove extra allocs --- helix-term/src/commands/typed.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 25288ad29..49864abb6 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1090,18 +1090,14 @@ fn change_current_directory( return Ok(()); } - let dir = match args.first() { - Some(Cow::Borrowed("-")) => cx + let dir = match args.first().map(AsRef::as_ref) { + Some("-") => cx .editor .last_cwd .clone() .ok_or(anyhow!("No previous working directory"))?, - Some(input_path) => { - helix_stdx::path::expand_tilde(Path::new(input_path.as_ref()).to_owned()) - .deref() - .to_path_buf() - } - None => home_dir()?.as_path().to_owned(), + Some(input_path) => helix_stdx::path::expand_tilde(Path::new(input_path)).to_path_buf(), + None => home_dir()?, }; cx.editor.last_cwd = helix_stdx::env::set_current_working_dir(dir)?;