Optimize saturating_add_signed
This commit is contained in:
parent
4846fd92c0
commit
47edde1086
@ -1037,10 +1037,13 @@ macro_rules! uint_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self {
|
pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self {
|
||||||
if rhs >= 0 {
|
let (res, overflow) = self.overflowing_add(rhs as Self);
|
||||||
self.saturating_add(rhs as Self)
|
if overflow == (rhs < 0) {
|
||||||
|
res
|
||||||
|
} else if overflow {
|
||||||
|
Self::MAX
|
||||||
} else {
|
} else {
|
||||||
self.saturating_sub(rhs.unsigned_abs())
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user