From a3fb1d618823ccab589fbca2b6d4cc3619900bc1 Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Thu, 15 Jul 2021 09:58:35 +0200 Subject: [PATCH] Make wrapping_neg() use wrapping_sub(), #[inline(always)] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- library/core/src/num/int_macros.rs | 4 ++-- library/core/src/num/uint_macros.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 982729388c87d..ac6cd2711d567 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1130,9 +1130,9 @@ macro_rules! int_impl { /// ``` #[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 diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ca1b05fdfbe48..97f3d17cf0860 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1245,9 +1245,9 @@ macro_rules! uint_impl { /// ``` #[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)`,