From: Alphyr <47725341+a1phyr@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:11:18 +0000 (+0200) Subject: Apply suggestion for `overflowing_add_signed` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=ab9f8a0b593a832f98188cd755bd467eeb9416d4;p=rust.git Apply suggestion for `overflowing_add_signed` Co-authored-by: kennytm --- diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 67d72a17135..2c4097a30a1 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1528,11 +1528,8 @@ pub const fn carrying_add(self, rhs: Self, carry: bool) -> (Self, bool) { without modifying the original"] #[inline] pub const fn overflowing_add_signed(self, rhs: $SignedT) -> (Self, bool) { - if rhs >= 0 { - self.overflowing_add(rhs as Self) - } else { - self.overflowing_sub(rhs.unsigned_abs()) - } + let (res, overflowed) = self.overflowing_add(rhs as Self); + (res, overflowed ^ (rhs < 0)) } /// Calculates `self` - `rhs`