Add missing #[inline] hints
This commit is contained in:
parent
47b8c7b5ae
commit
760604361d
|
@ -388,12 +388,12 @@ impl_from_primitive!(f64, to_f64);
|
|||
|
||||
|
||||
impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
|
||||
fn to_i64(&self) -> Option<i64> { self.0.to_i64() }
|
||||
fn to_u64(&self) -> Option<u64> { self.0.to_u64() }
|
||||
#[inline] fn to_i64(&self) -> Option<i64> { self.0.to_i64() }
|
||||
#[inline] fn to_u64(&self) -> Option<u64> { self.0.to_u64() }
|
||||
}
|
||||
impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
|
||||
fn from_u64(n: u64) -> Option<Self> { T::from_u64(n).map(Wrapping) }
|
||||
fn from_i64(n: i64) -> Option<Self> { T::from_i64(n).map(Wrapping) }
|
||||
#[inline] fn from_u64(n: u64) -> Option<Self> { T::from_u64(n).map(Wrapping) }
|
||||
#[inline] fn from_i64(n: i64) -> Option<Self> { T::from_i64(n).map(Wrapping) }
|
||||
}
|
||||
|
||||
|
||||
|
@ -447,6 +447,7 @@ impl_num_cast!(f32, to_f32);
|
|||
impl_num_cast!(f64, to_f64);
|
||||
|
||||
impl<T: NumCast> NumCast for Wrapping<T> {
|
||||
#[inline]
|
||||
fn from<U: ToPrimitive>(n: U) -> Option<Self> {
|
||||
T::from(n).map(Wrapping)
|
||||
}
|
||||
|
|
|
@ -52,9 +52,11 @@ zero_impl!(f32, 0.0f32);
|
|||
zero_impl!(f64, 0.0f64);
|
||||
|
||||
impl<T: Zero> Zero for Wrapping<T> where Wrapping<T>: Add<Output=Wrapping<T>> {
|
||||
#[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<T: One> One for Wrapping<T> where Wrapping<T>: Mul<Output=Wrapping<T>> {
|
||||
#[inline]
|
||||
fn one() -> Self {
|
||||
Wrapping(T::one())
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ impl<T: Num> Num for Wrapping<T>
|
|||
+ Mul<Output = Wrapping<T>> + Div<Output = Wrapping<T>> + Rem<Output = Wrapping<T>>
|
||||
{
|
||||
type FromStrRadixErr = T::FromStrRadixErr;
|
||||
#[inline]
|
||||
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> {
|
||||
T::from_str_radix(str, radix).map(Wrapping)
|
||||
}
|
||||
|
|
|
@ -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<T> to implement PrimInt.
|
||||
impl<T: CheckedAdd> CheckedAdd for Wrapping<T> where Wrapping<T>: Add<Output = Wrapping<T>>{
|
||||
#[inline]
|
||||
fn checked_add(&self, v: &Self) -> Option<Self> {
|
||||
self.0.checked_add(&v.0).map(Wrapping)
|
||||
}
|
||||
}
|
||||
impl<T: CheckedSub> CheckedSub for Wrapping<T> where Wrapping<T>: Sub<Output = Wrapping<T>> {
|
||||
#[inline]
|
||||
fn checked_sub(&self, v: &Self) -> Option<Self> {
|
||||
self.0.checked_sub(&v.0).map(Wrapping)
|
||||
}
|
||||
}
|
||||
impl<T: CheckedMul> CheckedMul for Wrapping<T> where Wrapping<T>: Mul<Output = Wrapping<T>>{
|
||||
#[inline]
|
||||
fn checked_mul(&self, v: &Self) -> Option<Self> {
|
||||
self.0.checked_mul(&v.0).map(Wrapping)
|
||||
}
|
||||
}
|
||||
impl<T: CheckedDiv> CheckedDiv for Wrapping<T> where Wrapping<T>: Div<Output = Wrapping<T>> {
|
||||
#[inline]
|
||||
fn checked_div(&self, v: &Self) -> Option<Self> {
|
||||
self.0.checked_div(&v.0).map(Wrapping)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ macro_rules! saturating_impl {
|
|||
saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
|
||||
|
||||
impl<T: Saturating> Saturating for Wrapping<T> {
|
||||
#[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)) }
|
||||
}
|
||||
|
|
|
@ -79,16 +79,19 @@ wrapping_impl!(WrappingMul, wrapping_mul, isize);
|
|||
|
||||
// Well this is a bit funny, but all the more appropriate.
|
||||
impl<T: WrappingAdd> WrappingAdd for Wrapping<T> where Wrapping<T>: Add<Output = Wrapping<T>> {
|
||||
#[inline]
|
||||
fn wrapping_add(&self, v: &Self) -> Self {
|
||||
Wrapping(self.0.wrapping_add(&v.0))
|
||||
}
|
||||
}
|
||||
impl<T: WrappingSub> WrappingSub for Wrapping<T> where Wrapping<T>: Sub<Output = Wrapping<T>> {
|
||||
#[inline]
|
||||
fn wrapping_sub(&self, v: &Self) -> Self {
|
||||
Wrapping(self.0.wrapping_sub(&v.0))
|
||||
}
|
||||
}
|
||||
impl<T: WrappingMul> WrappingMul for Wrapping<T> where Wrapping<T>: Mul<Output = Wrapping<T>> {
|
||||
#[inline]
|
||||
fn wrapping_mul(&self, v: &Self) -> Self {
|
||||
Wrapping(self.0.wrapping_mul(&v.0))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue