]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestion for `overflowing_add_signed`
authorAlphyr <47725341+a1phyr@users.noreply.github.com>
Fri, 30 Jul 2021 10:11:18 +0000 (12:11 +0200)
committerBenoît du Garreau <bdgdlm@outlook.com>
Fri, 1 Oct 2021 17:08:13 +0000 (19:08 +0200)
Co-authored-by: kennytm <kennytm@gmail.com>
library/core/src/num/uint_macros.rs

index 67d72a171350bae0f31a4219ed54fea85e8fd17a..2c4097a30a1e16a86e2deb15763cc43b84f3a728 100644 (file)
@@ -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`