From bc9725c73cf3bbce055df4a72b288341be526c06 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 27 Nov 2023 12:48:42 +0900 Subject: [PATCH] working_copy: use RepoPath::parent() which no longer allocates temporary object --- lib/src/local_working_copy.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 3d70f319b..7fdc30f30 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -301,13 +301,9 @@ fn create_parent_dirs( working_copy_path: &Path, repo_path: &RepoPath, ) -> Result { - // TODO: make RepoPath::parent() cheap and use it instead - let mut dir_components = repo_path.components(); - dir_components - .next_back() - .expect("repo path shouldn't be root"); + let parent_path = repo_path.parent().expect("repo path shouldn't be root"); let mut dir_path = working_copy_path.to_owned(); - for c in dir_components { + for c in parent_path.components() { dir_path.push(c.as_str()); match fs::create_dir(&dir_path) { Ok(()) => {}