Optimize inlining of math checked!() and expected!() predicates.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-03-03 05:57:54 +00:00
parent 59791db213
commit 7d5ed3f002

View File

@@ -14,7 +14,12 @@ use crate::{Err, Error, Result, debug::type_name, err};
macro_rules! checked {
($($input:tt)+) => {
$crate::utils::math::checked_ops!($($input)+)
.ok_or_else(|| $crate::err!(Arithmetic("operation overflowed or result invalid")))
.ok_or_else(
// The compiler will now attempt to inline the math predicate
// while moving the error handling out to .text.unlikely.
#[cold]
|| $crate::err!(Arithmetic("operation overflowed or result invalid"))
)
};
}