From 5ca36169f1e1609ba8a52bb792aa3a63a5df2b34 Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Fri, 24 Feb 2023 21:48:42 +0100 Subject: [PATCH] Avoid code bloat due to generics as very little of the clean function is actually generic. --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a800580..1aed5f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,13 +55,18 @@ impl PathClean for PathBuf { /// 5. Leave intact `..` elements that begin a non-rooted path. /// /// If the result of this process is an empty string, return the string `"."`, representing the current directory. +#[inline] pub fn clean

(path: P) -> PathBuf where P: AsRef, { + clean_impl(path.as_ref()) +} + +fn clean_impl(path: &Path) -> PathBuf { let mut out = Vec::new(); - for comp in path.as_ref().components() { + for comp in path.components() { match comp { Component::CurDir => (), Component::ParentDir => match out.last() {