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 e80f02c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/core/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ pub async fn run(

let mut scheduler = Scheduler {
stack: Vec::with_capacity(max_depth),
#[cfg(unix)]
target_dir: FastPathBuf::from(root_dir),
#[cfg(not(unix))]
target_dir: root_dir,

cache: {
let paths = Vec::with_capacity(tasks.capacity() / 2);
Expand Down
13 changes: 4 additions & 9 deletions src/utils/fast_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
ffi::OsStr,
fmt,
ops::{Deref, DerefMut},
os::unix::ffi::{OsStrExt, OsStringExt},
path::{Path, PathBuf, MAIN_SEPARATOR},
};

Expand Down Expand Up @@ -52,8 +51,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 All @@ -77,18 +76,14 @@ impl FastPathBuf {

impl From<PathBuf> for FastPathBuf {
fn from(p: PathBuf) -> Self {
let inner = p.into_os_string().into_vec();
let inner = p.into_os_string().into_encoded_bytes();
Self {
last_len: inner.len(),
inner,
}
}
}

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 +99,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 e80f02c

Please sign in to comment.