Stop using unlikely in strict_* methods

It's unnecessary when that arm leads to a `#[cold]` panic anyway, since controlling branch likihood is what `#[cold]` is all about.

(And, well, it's unclear whether `unlikely!` even works these days anyway.)
This commit is contained in:
Scott McMurray 2024-06-20 09:49:31 -07:00
parent 4e6de37349
commit a314f7363a
2 changed files with 19 additions and 19 deletions

View File

@ -484,7 +484,7 @@ pub const fn checked_add(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_add(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_add(rhs);
if unlikely!(b) { overflow_panic::add() } else { a }
if b { overflow_panic::add() } else { a }
}
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
@ -580,7 +580,7 @@ pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
#[track_caller]
pub const fn strict_add_unsigned(self, rhs: $UnsignedT) -> Self {
let (a, b) = self.overflowing_add_unsigned(rhs);
if unlikely!(b) { overflow_panic::add() } else { a }
if b { overflow_panic::add() } else { a }
}
/// Checked integer subtraction. Computes `self - rhs`, returning `None` if
@ -636,7 +636,7 @@ pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_sub(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_sub(rhs);
if unlikely!(b) { overflow_panic::sub() } else { a }
if b { overflow_panic::sub() } else { a }
}
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
@ -732,7 +732,7 @@ pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
#[track_caller]
pub const fn strict_sub_unsigned(self, rhs: $UnsignedT) -> Self {
let (a, b) = self.overflowing_sub_unsigned(rhs);
if unlikely!(b) { overflow_panic::sub() } else { a }
if b { overflow_panic::sub() } else { a }
}
/// Checked integer multiplication. Computes `self * rhs`, returning `None` if
@ -788,7 +788,7 @@ pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_mul(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_mul(rhs);
if unlikely!(b) { overflow_panic::mul() } else { a }
if b { overflow_panic::mul() } else { a }
}
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
@ -902,7 +902,7 @@ pub const fn checked_div(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_div(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_div(rhs);
if unlikely!(b) { overflow_panic::div() } else { a }
if b { overflow_panic::div() } else { a }
}
/// Checked Euclidean division. Computes `self.div_euclid(rhs)`,
@ -976,7 +976,7 @@ pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_div_euclid(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_div_euclid(rhs);
if unlikely!(b) { overflow_panic::div() } else { a }
if b { overflow_panic::div() } else { a }
}
/// Checked integer remainder. Computes `self % rhs`, returning `None` if
@ -1049,7 +1049,7 @@ pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_rem(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_rem(rhs);
if unlikely!(b) { overflow_panic::rem() } else { a }
if b { overflow_panic::rem() } else { a }
}
/// Checked Euclidean remainder. Computes `self.rem_euclid(rhs)`, returning `None`
@ -1122,7 +1122,7 @@ pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_rem_euclid(rhs);
if unlikely!(b) { overflow_panic::rem() } else { a }
if b { overflow_panic::rem() } else { a }
}
/// Checked negation. Computes `-self`, returning `None` if `self == MIN`.
@ -1210,7 +1210,7 @@ pub const fn checked_neg(self) -> Option<Self> {
#[track_caller]
pub const fn strict_neg(self) -> Self {
let (a, b) = self.overflowing_neg();
if unlikely!(b) { overflow_panic::neg() } else { a }
if b { overflow_panic::neg() } else { a }
}
/// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is larger
@ -1273,7 +1273,7 @@ pub const fn checked_shl(self, rhs: u32) -> Option<Self> {
#[track_caller]
pub const fn strict_shl(self, rhs: u32) -> Self {
let (a, b) = self.overflowing_shl(rhs);
if unlikely!(b) { overflow_panic::shl() } else { a }
if b { overflow_panic::shl() } else { a }
}
/// Unchecked shift left. Computes `self << rhs`, assuming that
@ -1371,7 +1371,7 @@ pub const fn checked_shr(self, rhs: u32) -> Option<Self> {
#[track_caller]
pub const fn strict_shr(self, rhs: u32) -> Self {
let (a, b) = self.overflowing_shr(rhs);
if unlikely!(b) { overflow_panic::shr() } else { a }
if b { overflow_panic::shr() } else { a }
}
/// Unchecked shift right. Computes `self >> rhs`, assuming that

View File

@ -491,7 +491,7 @@ pub const fn checked_add(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_add(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_add(rhs);
if unlikely!(b) { overflow_panic ::add()} else {a}
if b { overflow_panic::add() } else { a }
}
/// Unchecked integer addition. Computes `self + rhs`, assuming overflow
@ -593,7 +593,7 @@ pub const fn checked_add_signed(self, rhs: $SignedT) -> Option<Self> {
#[track_caller]
pub const fn strict_add_signed(self, rhs: $SignedT) -> Self {
let (a, b) = self.overflowing_add_signed(rhs);
if unlikely!(b) { overflow_panic ::add()} else {a}
if b { overflow_panic::add() } else { a }
}
/// Checked integer subtraction. Computes `self - rhs`, returning
@ -658,7 +658,7 @@ pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_sub(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_sub(rhs);
if unlikely!(b) { overflow_panic ::sub()} else {a}
if b { overflow_panic::sub() } else { a }
}
/// Unchecked integer subtraction. Computes `self - rhs`, assuming overflow
@ -779,7 +779,7 @@ pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
#[track_caller]
pub const fn strict_mul(self, rhs: Self) -> Self {
let (a, b) = self.overflowing_mul(rhs);
if unlikely!(b) { overflow_panic ::mul()} else {a}
if b { overflow_panic::mul() } else { a }
}
/// Unchecked integer multiplication. Computes `self * rhs`, assuming overflow
@ -1304,7 +1304,7 @@ pub const fn checked_neg(self) -> Option<Self> {
#[track_caller]
pub const fn strict_neg(self) -> Self {
let (a, b) = self.overflowing_neg();
if unlikely!(b) { overflow_panic::neg() } else { a }
if b { overflow_panic::neg() } else { a }
}
/// Checked shift left. Computes `self << rhs`, returning `None`
@ -1367,7 +1367,7 @@ pub const fn checked_shl(self, rhs: u32) -> Option<Self> {
#[track_caller]
pub const fn strict_shl(self, rhs: u32) -> Self {
let (a, b) = self.overflowing_shl(rhs);
if unlikely!(b) { overflow_panic::shl() } else { a }
if b { overflow_panic::shl() } else { a }
}
/// Unchecked shift left. Computes `self << rhs`, assuming that
@ -1465,7 +1465,7 @@ pub const fn checked_shr(self, rhs: u32) -> Option<Self> {
#[track_caller]
pub const fn strict_shr(self, rhs: u32) -> Self {
let (a, b) = self.overflowing_shr(rhs);
if unlikely!(b) { overflow_panic::shr() } else { a }
if b { overflow_panic::shr() } else { a }
}
/// Unchecked shift right. Computes `self >> rhs`, assuming that