From 43fb2749566ad554adfc560f50e65acff8f1d90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Miguel?= <36349314+vrmiguel@users.noreply.github.com> Date: Fri, 5 Nov 2021 23:49:35 -0400 Subject: [PATCH] Optimize `strip_cur_dir` (#167) --- src/utils/fs.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/utils/fs.rs b/src/utils/fs.rs index be374f4..00bfcdd 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -30,11 +30,8 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { /// Removes the current dir from the beginning of a path /// normally used for presentation sake. /// If this function fails, it will return source path as a PathBuf. -pub fn strip_cur_dir(source_path: &Path) -> PathBuf { - source_path - .strip_prefix(Component::CurDir) - .map(|path| path.to_path_buf()) - .unwrap_or_else(|_| source_path.to_path_buf()) +pub fn strip_cur_dir(source_path: &Path) -> &Path { + source_path.strip_prefix(Component::CurDir).unwrap_or(source_path) } /// Returns current directory, but before change the process' directory to the