Add a simple optimization to normalize_path

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-15 17:52:49 +10:00
parent 30b9a78520
commit 39ab334da5
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -30,9 +30,10 @@ impl PathExt for Path {
} }
let mut components = self.components().peekable(); let mut components = self.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek() {
let buf = PathBuf::from(c.as_os_str());
components.next(); components.next();
PathBuf::from(c.as_os_str()) buf
} else { } else {
PathBuf::new() PathBuf::new()
}; };