Make wrapping_neg() use wrapping_sub(), #[inline(always)]

This is a follow-up change to the fix for #75598. It simplifies the implementation of wrapping_neg() for all integer types by just calling 0.wrapping_sub(self) and always inlines it. This leads to much less assembly code being emitted for opt-level≤1.
This commit is contained in:
Hans Kratz 2021-07-15 09:58:35 +02:00
parent b9197978a9
commit a3fb1d6188
2 changed files with 4 additions and 4 deletions

View File

@ -1130,9 +1130,9 @@ pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
#[inline]
#[inline(always)]
pub const fn wrapping_neg(self) -> Self {
self.overflowing_neg().0
(0 as $SelfT).wrapping_sub(self)
}
/// Panic-free bitwise shift-left; yields `self << mask(rhs)`, where `mask` removes

View File

@ -1245,9 +1245,9 @@ pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
#[inline]
#[inline(always)]
pub const fn wrapping_neg(self) -> Self {
self.overflowing_neg().0
(0 as $SelfT).wrapping_sub(self)
}
/// Panic-free bitwise shift-left; yields `self << mask(rhs)`,