From f5dae9106e7aa80823ec5728fa721a6d0b184deb Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 16 Feb 2022 17:25:26 +1100 Subject: [PATCH] Inline safe_arith methods --- consensus/safe_arith/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/consensus/safe_arith/src/lib.rs b/consensus/safe_arith/src/lib.rs index ab5985a6e1..c1dbff4c7c 100644 --- a/consensus/safe_arith/src/lib.rs +++ b/consensus/safe_arith/src/lib.rs @@ -20,6 +20,7 @@ macro_rules! assign_method { #[doc = "Safe variant of `"] #[doc = $doc_op] #[doc = "`."] + #[inline] fn $name(&mut self, other: $rhs_ty) -> Result<()> { *self = self.$op(other)?; Ok(()) @@ -68,30 +69,37 @@ macro_rules! impl_safe_arith { const ZERO: Self = 0; const ONE: Self = 1; + #[inline] fn safe_add(&self, other: Self) -> Result { self.checked_add(other).ok_or(ArithError::Overflow) } + #[inline] fn safe_sub(&self, other: Self) -> Result { self.checked_sub(other).ok_or(ArithError::Overflow) } + #[inline] fn safe_mul(&self, other: Self) -> Result { self.checked_mul(other).ok_or(ArithError::Overflow) } + #[inline] fn safe_div(&self, other: Self) -> Result { self.checked_div(other).ok_or(ArithError::DivisionByZero) } + #[inline] fn safe_rem(&self, other: Self) -> Result { self.checked_rem(other).ok_or(ArithError::DivisionByZero) } + #[inline] fn safe_shl(&self, other: u32) -> Result { self.checked_shl(other).ok_or(ArithError::Overflow) } + #[inline] fn safe_shr(&self, other: u32) -> Result { self.checked_shr(other).ok_or(ArithError::Overflow) }