From 4a1552cc0e72333bfd3b0813fa48998ef62617a9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 26 Sep 2022 12:19:43 -0500 Subject: [PATCH] perf: Drop use of Into::into for '?' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For binary size, this only dropped 0.2 KiB For performance, before: - parse_rustup_with_sc time: [7.9866 µs 8.0138 µs 8.0470 µs] After: - parse_rustup_with_sc time: [7.5387 µs 7.5722 µs 7.6157 µs] For build-time, before ```console $ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example" Benchmark 1: cargo build -F cargo --example cargo-example Time (mean ± σ): 16.988 s ± 1.190 s [User: 68.178 s, System: 6.637 s] Range (min … max): 15.550 s … 18.277 s 5 runs ``` After: ```console $ hyperfine --warmup=1 --min-runs=5 "--prepare=cargo clean" "cargo build -F cargo --example cargo-example" Benchmark 1: cargo build -F cargo --example cargo-example Time (mean ± σ): 15.674 s ± 0.222 s [User: 62.287 s, System: 4.608 s] Range (min … max): 15.426 s … 15.993 s 5 runs ``` --- src/macros.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index decdc491..df0680ff 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -664,12 +664,22 @@ macro_rules! debug { macro_rules! ok { ($expr:expr) => { - $expr? + match $expr { + Ok(val) => val, + Err(err) => { + return Err(err); + } + } }; } macro_rules! some { ($expr:expr) => { - $expr? + match $expr { + Some(val) => val, + None => { + return None; + } + } }; }