mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-28 05:21:34 +00:00
Eliminate backtrace_if_absent in Error::context
This avoids stepping through the list of causes when adding context to the anyhow::Error type which is known to already hold a backtrace. Reduces the release-mode time of the following loop from 4 seconds to 4 milliseconds. let mut err = anyhow!("..."); for _ in 0..25000 { err = err.context("..."); }
This commit is contained in:
parent
8885e93ca6
commit
a2846fd345
19
src/error.rs
19
src/error.rs
@ -167,10 +167,25 @@ impl Error {
|
||||
where
|
||||
C: Display + Send + Sync + 'static,
|
||||
{
|
||||
Error::new(ContextError {
|
||||
let error = ContextError {
|
||||
context,
|
||||
error: self,
|
||||
})
|
||||
};
|
||||
|
||||
let vtable = &ErrorVTable {
|
||||
object_drop: object_drop::<ContextError<C, Error>>,
|
||||
object_drop_front: object_drop_front::<ContextError<C, Error>>,
|
||||
object_ref: object_ref::<ContextError<C, Error>>,
|
||||
object_mut: object_mut::<ContextError<C, Error>>,
|
||||
object_boxed: object_boxed::<ContextError<C, Error>>,
|
||||
object_is: object_is::<ContextError<C, Error>>,
|
||||
};
|
||||
|
||||
// As the cause is anyhow::Error, we already have a backtrace for it.
|
||||
let backtrace = None;
|
||||
|
||||
// Safety: passing vtable that operates on the right type.
|
||||
unsafe { Error::construct(error, vtable, backtrace) }
|
||||
}
|
||||
|
||||
/// Get the backtrace for this Error.
|
||||
|
Loading…
x
Reference in New Issue
Block a user