Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl ResolveError {
matches!(self, Self::Ignored(_))
}

#[cold]
#[must_use]
pub fn from_serde_json_error(path: PathBuf, error: &serde_json::Error) -> Self {
Self::Json(JSONError {
Expand Down Expand Up @@ -163,13 +164,15 @@ impl PartialEq for IOError {
}

impl From<IOError> for io::Error {
#[cold]
fn from(error: IOError) -> Self {
let io_error = error.0.as_ref();
Self::new(io_error.kind(), io_error.to_string())
}
}

impl From<io::Error> for ResolveError {
#[cold]
fn from(err: io::Error) -> Self {
Self::IOError(IOError(Arc::new(err)))
}
Expand All @@ -191,6 +194,7 @@ impl Display for CircularPathBufs {
}

impl From<Vec<PathBuf>> for CircularPathBufs {
#[cold]
fn from(value: Vec<PathBuf>) -> Self {
Self(value)
}
Expand Down
9 changes: 5 additions & 4 deletions src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ impl FileSystemOs {
// `simdutf8` is faster than `std::str::from_utf8` which `fs::read_to_string` uses internally
if simdutf8::basic::from_utf8(&bytes).is_err() {
// Same error as `fs::read_to_string` produces (`io::Error::INVALID_UTF8`)
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"stream did not contain valid UTF-8",
));
#[cold]
fn invalid_utf8_error() -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, "stream did not contain valid UTF-8")
}
return Err(invalid_utf8_error());
}
// SAFETY: `simdutf8` has ensured it's a valid UTF-8 string
Ok(unsafe { String::from_utf8_unchecked(bytes) })
Expand Down
12 changes: 10 additions & 2 deletions src/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ impl<'a> Specifier<'a> {

pub fn parse(specifier: &'a str) -> Result<Self, SpecifierError> {
if specifier.is_empty() {
return Err(SpecifierError::Empty(specifier.to_string()));
#[cold]
fn empty_specifier_error(specifier: &str) -> SpecifierError {
SpecifierError::Empty(specifier.to_string())
}
return Err(empty_specifier_error(specifier));
}
let offset = match specifier.as_bytes()[0] {
b'/' | b'.' | b'#' => 1,
_ => 0,
};
let (path, query, fragment) = Self::parse_query_fragment(specifier, offset);
if path.is_empty() {
return Err(SpecifierError::Empty(specifier.to_string()));
#[cold]
fn empty_path_error(specifier: &str) -> SpecifierError {
SpecifierError::Empty(specifier.to_string())
}
return Err(empty_path_error(specifier));
}
Ok(Self { path, query, fragment })
}
Expand Down
6 changes: 5 additions & 1 deletion src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub fn strip_windows_prefix(path: PathBuf) -> Result<PathBuf, ResolveError> {
// \\?\BootPartition\
// It seems nodejs does not support DOS device paths with Volume GUIDs.
// This can happen if the path points to a Mounted Volume without a drive letter.
return Err(ResolveError::PathNotSupported(path));
#[cold]
fn unsupported_path_error(path: PathBuf) -> ResolveError {
ResolveError::PathNotSupported(path)
}
return Err(unsupported_path_error(path));
}
// SAFETY: `as_encoded_bytes` ensures `p` is valid path bytes
unsafe { PathBuf::from(std::ffi::OsStr::from_encoded_bytes_unchecked(p)) }
Expand Down
Loading