From 6a8f671056703664506a8a3f4198a3deaebefb11 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 4 Jan 2024 23:28:28 -0800 Subject: [PATCH] Use FastPathBuf on Windows since OsStr::from_encoded_bytes_unchecked is a thing now Signed-off-by: Alex Saveau --- src/utils/fast_path.rs | 10 +++------- src/utils/mod.rs | 9 ++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/utils/fast_path.rs b/src/utils/fast_path.rs index a0ea106..3483c73 100644 --- a/src/utils/fast_path.rs +++ b/src/utils/fast_path.rs @@ -52,8 +52,8 @@ impl FastPathBuf { if inner.len() > last_len { inner.truncate(last_len); } else { - inner.truncate({ - let parent = bytes_as_path(inner).parent(); + self.inner.truncate({ + let parent = self.parent(); let parent = unsafe { parent.unwrap_unchecked() }; parent.as_os_str().len() }); @@ -85,10 +85,6 @@ impl From for FastPathBuf { } } -fn bytes_as_path(bytes: &[u8]) -> &Path { - OsStr::from_bytes(bytes).as_ref() -} - impl Default for FastPathBuf { fn default() -> Self { Self::new() @@ -104,7 +100,7 @@ impl Deref for FastPathBuf { last_len: _, } = *self; - bytes_as_path(inner) + unsafe { OsStr::from_encoded_bytes_unchecked(inner) }.as_ref() } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index f61388a..30b1545 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,10 +1,5 @@ -#[cfg(unix)] -mod fast_path; -#[cfg(not(unix))] -pub use std::path::PathBuf as FastPathBuf; - -#[cfg(unix)] pub use fast_path::FastPathBuf; +pub use file_names::*; +mod fast_path; mod file_names; -pub use file_names::*;