diff --git a/src/error.rs b/src/error.rs index a4384da7..219e2550 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 { @@ -163,6 +164,7 @@ impl PartialEq for IOError { } impl From 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()) @@ -170,6 +172,7 @@ impl From for io::Error { } impl From for ResolveError { + #[cold] fn from(err: io::Error) -> Self { Self::IOError(IOError(Arc::new(err))) } @@ -191,6 +194,7 @@ impl Display for CircularPathBufs { } impl From> for CircularPathBufs { + #[cold] fn from(value: Vec) -> Self { Self(value) } diff --git a/src/file_system.rs b/src/file_system.rs index e0a71f3b..dcc6d58f 100644 --- a/src/file_system.rs +++ b/src/file_system.rs @@ -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) }) diff --git a/src/specifier.rs b/src/specifier.rs index 44b45843..d757b378 100644 --- a/src/specifier.rs +++ b/src/specifier.rs @@ -16,7 +16,11 @@ impl<'a> Specifier<'a> { pub fn parse(specifier: &'a str) -> Result { 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, @@ -24,7 +28,11 @@ impl<'a> Specifier<'a> { }; 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 }) } diff --git a/src/windows/mod.rs b/src/windows/mod.rs index b8bada92..6b24ee4a 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -33,7 +33,11 @@ pub fn strip_windows_prefix(path: PathBuf) -> Result { // \\?\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)) }