From 7bc7ddfc87b88e928cc5bc5aa090ebe756fa52fb Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:21:00 -0700 Subject: [PATCH 1/6] traits: inline PrimInt methods --- traits/src/int.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/traits/src/int.rs b/traits/src/int.rs index 6cc90ca..0cf9e13 100644 --- a/traits/src/int.rs +++ b/traits/src/int.rs @@ -280,66 +280,82 @@ pub trait PrimInt macro_rules! prim_int_impl { ($T:ty, $S:ty, $U:ty) => ( impl PrimInt for $T { + #[inline] fn count_ones(self) -> u32 { <$T>::count_ones(self) } + #[inline] fn count_zeros(self) -> u32 { <$T>::count_zeros(self) } + #[inline] fn leading_zeros(self) -> u32 { <$T>::leading_zeros(self) } + #[inline] fn trailing_zeros(self) -> u32 { <$T>::trailing_zeros(self) } + #[inline] fn rotate_left(self, n: u32) -> Self { <$T>::rotate_left(self, n) } + #[inline] fn rotate_right(self, n: u32) -> Self { <$T>::rotate_right(self, n) } + #[inline] fn signed_shl(self, n: u32) -> Self { ((self as $S) << n) as $T } + #[inline] fn signed_shr(self, n: u32) -> Self { ((self as $S) >> n) as $T } + #[inline] fn unsigned_shl(self, n: u32) -> Self { ((self as $U) << n) as $T } + #[inline] fn unsigned_shr(self, n: u32) -> Self { ((self as $U) >> n) as $T } + #[inline] fn swap_bytes(self) -> Self { <$T>::swap_bytes(self) } + #[inline] fn from_be(x: Self) -> Self { <$T>::from_be(x) } + #[inline] fn from_le(x: Self) -> Self { <$T>::from_le(x) } + #[inline] fn to_be(self) -> Self { <$T>::to_be(self) } + #[inline] fn to_le(self) -> Self { <$T>::to_le(self) } + #[inline] fn pow(self, exp: u32) -> Self { <$T>::pow(self, exp) } From eefa2a85d0b15b3148df3080f4c2e175a58741ac Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:21:33 -0700 Subject: [PATCH 2/6] traits: inline Float methods --- traits/src/float.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/traits/src/float.rs b/traits/src/float.rs index 1445dd3..cbc8395 100644 --- a/traits/src/float.rs +++ b/traits/src/float.rs @@ -515,6 +515,7 @@ pub trait Float /// /// assert!(abs_difference < 1e-10); /// ``` + #[inline] fn to_degrees(self) -> Self { let halfpi = Self::zero().acos(); let ninety = Self::from(90u8).unwrap(); @@ -532,6 +533,7 @@ pub trait Float /// /// assert!(abs_difference < 1e-10); /// ``` + #[inline] fn to_radians(self) -> Self { let halfpi = Self::zero().acos(); let ninety = Self::from(90u8).unwrap(); @@ -904,231 +906,287 @@ pub trait Float macro_rules! float_impl { ($T:ident $decode:ident) => ( impl Float for $T { + #[inline] fn nan() -> Self { ::std::$T::NAN } + #[inline] fn infinity() -> Self { ::std::$T::INFINITY } + #[inline] fn neg_infinity() -> Self { ::std::$T::NEG_INFINITY } + #[inline] fn neg_zero() -> Self { -0.0 } + #[inline] fn min_value() -> Self { ::std::$T::MIN } + #[inline] fn min_positive_value() -> Self { ::std::$T::MIN_POSITIVE } + #[inline] fn max_value() -> Self { ::std::$T::MAX } + #[inline] fn is_nan(self) -> bool { <$T>::is_nan(self) } + #[inline] fn is_infinite(self) -> bool { <$T>::is_infinite(self) } + #[inline] fn is_finite(self) -> bool { <$T>::is_finite(self) } + #[inline] fn is_normal(self) -> bool { <$T>::is_normal(self) } + #[inline] fn classify(self) -> FpCategory { <$T>::classify(self) } + #[inline] fn floor(self) -> Self { <$T>::floor(self) } + #[inline] fn ceil(self) -> Self { <$T>::ceil(self) } + #[inline] fn round(self) -> Self { <$T>::round(self) } + #[inline] fn trunc(self) -> Self { <$T>::trunc(self) } + #[inline] fn fract(self) -> Self { <$T>::fract(self) } + #[inline] fn abs(self) -> Self { <$T>::abs(self) } + #[inline] fn signum(self) -> Self { <$T>::signum(self) } + #[inline] fn is_sign_positive(self) -> bool { <$T>::is_sign_positive(self) } + #[inline] fn is_sign_negative(self) -> bool { <$T>::is_sign_negative(self) } + #[inline] fn mul_add(self, a: Self, b: Self) -> Self { <$T>::mul_add(self, a, b) } + #[inline] fn recip(self) -> Self { <$T>::recip(self) } + #[inline] fn powi(self, n: i32) -> Self { <$T>::powi(self, n) } + #[inline] fn powf(self, n: Self) -> Self { <$T>::powf(self, n) } + #[inline] fn sqrt(self) -> Self { <$T>::sqrt(self) } + #[inline] fn exp(self) -> Self { <$T>::exp(self) } + #[inline] fn exp2(self) -> Self { <$T>::exp2(self) } + #[inline] fn ln(self) -> Self { <$T>::ln(self) } + #[inline] fn log(self, base: Self) -> Self { <$T>::log(self, base) } + #[inline] fn log2(self) -> Self { <$T>::log2(self) } + #[inline] fn log10(self) -> Self { <$T>::log10(self) } + #[inline] fn to_degrees(self) -> Self { // NB: `f32` didn't stabilize this until 1.7 // <$T>::to_degrees(self) self * (180. / ::std::$T::consts::PI) } + #[inline] fn to_radians(self) -> Self { // NB: `f32` didn't stabilize this until 1.7 // <$T>::to_radians(self) self * (::std::$T::consts::PI / 180.) } + #[inline] fn max(self, other: Self) -> Self { <$T>::max(self, other) } + #[inline] fn min(self, other: Self) -> Self { <$T>::min(self, other) } + #[inline] #[allow(deprecated)] fn abs_sub(self, other: Self) -> Self { <$T>::abs_sub(self, other) } + #[inline] fn cbrt(self) -> Self { <$T>::cbrt(self) } + #[inline] fn hypot(self, other: Self) -> Self { <$T>::hypot(self, other) } + #[inline] fn sin(self) -> Self { <$T>::sin(self) } + #[inline] fn cos(self) -> Self { <$T>::cos(self) } + #[inline] fn tan(self) -> Self { <$T>::tan(self) } + #[inline] fn asin(self) -> Self { <$T>::asin(self) } + #[inline] fn acos(self) -> Self { <$T>::acos(self) } + #[inline] fn atan(self) -> Self { <$T>::atan(self) } + #[inline] fn atan2(self, other: Self) -> Self { <$T>::atan2(self, other) } + #[inline] fn sin_cos(self) -> (Self, Self) { <$T>::sin_cos(self) } + #[inline] fn exp_m1(self) -> Self { <$T>::exp_m1(self) } + #[inline] fn ln_1p(self) -> Self { <$T>::ln_1p(self) } + #[inline] fn sinh(self) -> Self { <$T>::sinh(self) } + #[inline] fn cosh(self) -> Self { <$T>::cosh(self) } + #[inline] fn tanh(self) -> Self { <$T>::tanh(self) } + #[inline] fn asinh(self) -> Self { <$T>::asinh(self) } + #[inline] fn acosh(self) -> Self { <$T>::acosh(self) } + #[inline] fn atanh(self) -> Self { <$T>::atanh(self) } + #[inline] fn integer_decode(self) -> (u64, i16, i8) { $decode(self) } From fa451ac00c372ac8ca55265735406f4f49ec4bbd Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:21:53 -0700 Subject: [PATCH 3/6] traits: inline Saturating methods --- traits/src/ops/saturating.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/traits/src/ops/saturating.rs b/traits/src/ops/saturating.rs index 15f06b7..e9db749 100644 --- a/traits/src/ops/saturating.rs +++ b/traits/src/ops/saturating.rs @@ -12,10 +12,12 @@ pub trait Saturating { macro_rules! saturating_impl { ($trait_name:ident for $($t:ty)*) => {$( impl $trait_name for $t { + #[inline] fn saturating_add(self, v: Self) -> Self { Self::saturating_add(self, v) } + #[inline] fn saturating_sub(self, v: Self) -> Self { Self::saturating_sub(self, v) } From 7a9c39fa87d0a73737aa3232ce36ee3dae3da705 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:22:15 -0700 Subject: [PATCH 4/6] traits: inline Bounded tuple methods --- traits/src/bounds.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/traits/src/bounds.rs b/traits/src/bounds.rs index 9f527d7..966296c 100644 --- a/traits/src/bounds.rs +++ b/traits/src/bounds.rs @@ -55,9 +55,11 @@ macro_rules! for_each_tuple { macro_rules! bounded_tuple { ( $($name:ident)* ) => ( impl<$($name: Bounded,)*> Bounded for ($($name,)*) { + #[inline] fn min_value() -> Self { ($($name::min_value(),)*) } + #[inline] fn max_value() -> Self { ($($name::max_value(),)*) } From 932e45c2076f06d13e7341e369080fb2b95146d3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:22:53 -0700 Subject: [PATCH 5/6] traits: inline integer from_str_radix --- traits/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/traits/src/lib.rs b/traits/src/lib.rs index 13f8cf7..2113ea6 100644 --- a/traits/src/lib.rs +++ b/traits/src/lib.rs @@ -46,6 +46,7 @@ macro_rules! int_trait_impl { ($name:ident for $($t:ty)*) => ($( impl $name for $t { type FromStrRadixErr = ::std::num::ParseIntError; + #[inline] fn from_str_radix(s: &str, radix: u32) -> Result { From 5c3d759d6c4c2e1cb4f55cf29db0300191650d07 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 10 Aug 2016 22:23:28 -0700 Subject: [PATCH 6/6] bigint: inline bits() methods --- bigint/src/bigint.rs | 1 + bigint/src/biguint.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/bigint/src/bigint.rs b/bigint/src/bigint.rs index 6cf7486..7a9b02d 100644 --- a/bigint/src/bigint.rs +++ b/bigint/src/bigint.rs @@ -1068,6 +1068,7 @@ impl BigInt { /// Determines the fewest bits necessary to express the `BigInt`, /// not including the sign. + #[inline] pub fn bits(&self) -> usize { self.data.bits() } diff --git a/bigint/src/biguint.rs b/bigint/src/biguint.rs index b9dfa19..5248115 100644 --- a/bigint/src/biguint.rs +++ b/bigint/src/biguint.rs @@ -1049,6 +1049,7 @@ impl BigUint { } /// Determines the fewest bits necessary to express the `BigUint`. + #[inline] pub fn bits(&self) -> usize { if self.is_zero() { return 0;