Skip to content

Commit

Permalink
Use FastPathBuf on Windows since OsStr::from_encoded_bytes_unchecked …
Browse files Browse the repository at this point in the history
…is a thing now

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
SUPERCILEX committed Jan 5, 2024
1 parent c521dca commit 6a8f671
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/utils/fast_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
Expand Down Expand Up @@ -85,10 +85,6 @@ impl From<PathBuf> for FastPathBuf {
}
}

fn bytes_as_path(bytes: &[u8]) -> &Path {
OsStr::from_bytes(bytes).as_ref()
}

impl Default for FastPathBuf {
fn default() -> Self {
Self::new()
Expand All @@ -104,7 +100,7 @@ impl Deref for FastPathBuf {
last_len: _,
} = *self;

bytes_as_path(inner)
unsafe { OsStr::from_encoded_bytes_unchecked(inner) }.as_ref()
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;

0 comments on commit 6a8f671

Please sign in to comment.