From 760604361d0f4d1dd014da0047a27f5775d1b26e Mon Sep 17 00:00:00 2001 From: Yoan Lecoq Date: Sat, 29 Apr 2017 08:35:37 +0200 Subject: [PATCH] Add missing #[inline] hints --- traits/src/cast.rs | 9 +++++---- traits/src/identities.rs | 3 +++ traits/src/lib.rs | 1 + traits/src/ops/checked.rs | 4 ++++ traits/src/ops/saturating.rs | 2 ++ traits/src/ops/wrapping.rs | 3 +++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/traits/src/cast.rs b/traits/src/cast.rs index eda58f5..7d1807d 100644 --- a/traits/src/cast.rs +++ b/traits/src/cast.rs @@ -388,12 +388,12 @@ impl_from_primitive!(f64, to_f64); impl ToPrimitive for Wrapping { - fn to_i64(&self) -> Option { self.0.to_i64() } - fn to_u64(&self) -> Option { self.0.to_u64() } + #[inline] fn to_i64(&self) -> Option { self.0.to_i64() } + #[inline] fn to_u64(&self) -> Option { self.0.to_u64() } } impl FromPrimitive for Wrapping { - fn from_u64(n: u64) -> Option { T::from_u64(n).map(Wrapping) } - fn from_i64(n: i64) -> Option { T::from_i64(n).map(Wrapping) } + #[inline] fn from_u64(n: u64) -> Option { T::from_u64(n).map(Wrapping) } + #[inline] fn from_i64(n: i64) -> Option { T::from_i64(n).map(Wrapping) } } @@ -447,6 +447,7 @@ impl_num_cast!(f32, to_f32); impl_num_cast!(f64, to_f64); impl NumCast for Wrapping { + #[inline] fn from(n: U) -> Option { T::from(n).map(Wrapping) } diff --git a/traits/src/identities.rs b/traits/src/identities.rs index 889b11d..dea7b9c 100644 --- a/traits/src/identities.rs +++ b/traits/src/identities.rs @@ -52,9 +52,11 @@ zero_impl!(f32, 0.0f32); zero_impl!(f64, 0.0f64); impl Zero for Wrapping where Wrapping: Add> { + #[inline] fn is_zero(&self) -> bool { self.0.is_zero() } + #[inline] fn zero() -> Self { Wrapping(T::zero()) } @@ -106,6 +108,7 @@ one_impl!(f32, 1.0f32); one_impl!(f64, 1.0f64); impl One for Wrapping where Wrapping: Mul> { + #[inline] fn one() -> Self { Wrapping(T::one()) } diff --git a/traits/src/lib.rs b/traits/src/lib.rs index 0cf7e34..ce5599b 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -81,6 +81,7 @@ impl Num for Wrapping + Mul> + Div> + Rem> { type FromStrRadixErr = T::FromStrRadixErr; + #[inline] fn from_str_radix(str: &str, radix: u32) -> Result { T::from_str_radix(str, radix).map(Wrapping) } diff --git a/traits/src/ops/checked.rs b/traits/src/ops/checked.rs index 4437acb..a2df6d1 100644 --- a/traits/src/ops/checked.rs +++ b/traits/src/ops/checked.rs @@ -98,21 +98,25 @@ checked_impl!(CheckedDiv, checked_div, isize); // and only have a handful of places where they want to perform checked ops; // - This allows Wrapping to implement PrimInt. impl CheckedAdd for Wrapping where Wrapping: Add>{ + #[inline] fn checked_add(&self, v: &Self) -> Option { self.0.checked_add(&v.0).map(Wrapping) } } impl CheckedSub for Wrapping where Wrapping: Sub> { + #[inline] fn checked_sub(&self, v: &Self) -> Option { self.0.checked_sub(&v.0).map(Wrapping) } } impl CheckedMul for Wrapping where Wrapping: Mul>{ + #[inline] fn checked_mul(&self, v: &Self) -> Option { self.0.checked_mul(&v.0).map(Wrapping) } } impl CheckedDiv for Wrapping where Wrapping: Div> { + #[inline] fn checked_div(&self, v: &Self) -> Option { self.0.checked_div(&v.0).map(Wrapping) } diff --git a/traits/src/ops/saturating.rs b/traits/src/ops/saturating.rs index ebbbe51..2a4f711 100644 --- a/traits/src/ops/saturating.rs +++ b/traits/src/ops/saturating.rs @@ -30,6 +30,8 @@ macro_rules! saturating_impl { saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64); impl Saturating for Wrapping { + #[inline] fn saturating_add(self, v: Self) -> Self { Wrapping(self.0.saturating_add(v.0)) } + #[inline] fn saturating_sub(self, v: Self) -> Self { Wrapping(self.0.saturating_sub(v.0)) } } diff --git a/traits/src/ops/wrapping.rs b/traits/src/ops/wrapping.rs index cd68ac4..29981a4 100644 --- a/traits/src/ops/wrapping.rs +++ b/traits/src/ops/wrapping.rs @@ -79,16 +79,19 @@ wrapping_impl!(WrappingMul, wrapping_mul, isize); // Well this is a bit funny, but all the more appropriate. impl WrappingAdd for Wrapping where Wrapping: Add> { + #[inline] fn wrapping_add(&self, v: &Self) -> Self { Wrapping(self.0.wrapping_add(&v.0)) } } impl WrappingSub for Wrapping where Wrapping: Sub> { + #[inline] fn wrapping_sub(&self, v: &Self) -> Self { Wrapping(self.0.wrapping_sub(&v.0)) } } impl WrappingMul for Wrapping where Wrapping: Mul> { + #[inline] fn wrapping_mul(&self, v: &Self) -> Self { Wrapping(self.0.wrapping_mul(&v.0)) }