From fa6ce4205650d448f8adb283983ba91669a177ee Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 21 Sep 2022 21:36:44 -0700 Subject: [PATCH] Redefine 'try' macro to omit From::from error conversion --- serde/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/serde/src/lib.rs b/serde/src/lib.rs index f3ff27e5..71bd43e3 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -249,6 +249,19 @@ mod lib { pub use self::core::time::Duration; } +// None of this crate's error handling needs the `From::from` error conversion +// performed implicitly by the `?` operator or the standard library's `try!` +// macro. This simplified macro gives a 5.5% improvement in compile time +// compared to standard `try!`, and 9% improvement compared to `?`. +macro_rules! try { + ($expr:expr) => { + match $expr { + Ok(val) => val, + Err(err) => return Err(err), + } + }; +} + //////////////////////////////////////////////////////////////////////////////// #[macro_use]