Skip to content

Commit

Permalink
Mark core Error methods as #[cold]
Browse files Browse the repository at this point in the history
Basically all error handling paths are assumed to be cold and only
rarely called. Convey that to the compiler by marking two of the core
ones as #[cold], so that it can try and generate better code as a
result. This attribute should transitively affect all call-sites.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Oct 24, 2024
1 parent 0e769da commit d246369
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub struct Error {
}

impl Error {
#[inline]
#[cold]
fn with_io_error<E>(kind: io::ErrorKind, error: E) -> Self
where
E: ToString,
Expand Down Expand Up @@ -482,6 +482,7 @@ impl Error {

/// Layer the provided context on top of this `Error`, creating a
/// new one in the process.
#[cold]
fn layer_context(self, context: Cow<'static, Str>) -> Self {
match context {
Cow::Owned(context) => Self {
Expand Down

0 comments on commit d246369

Please sign in to comment.