Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using unlikely in strict_* methods #126750

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -580,7 +580,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -636,7 +636,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -732,7 +732,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -788,7 +788,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -902,7 +902,7 @@ macro_rules! int_impl {
#[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)`,
Expand Down Expand Up @@ -976,7 +976,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -1049,7 +1049,7 @@ macro_rules! int_impl {
#[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`
Expand Down Expand Up @@ -1122,7 +1122,7 @@ macro_rules! int_impl {
#[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`.
Expand Down Expand Up @@ -1210,7 +1210,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -1273,7 +1273,7 @@ macro_rules! int_impl {
#[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
Expand Down Expand Up @@ -1371,7 +1371,7 @@ macro_rules! int_impl {
#[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
Expand Down
14 changes: 7 additions & 7 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ macro_rules! uint_impl {
#[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
Expand Down Expand Up @@ -593,7 +593,7 @@ macro_rules! uint_impl {
#[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
Expand Down Expand Up @@ -658,7 +658,7 @@ macro_rules! uint_impl {
#[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
Expand Down Expand Up @@ -779,7 +779,7 @@ macro_rules! uint_impl {
#[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
Expand Down Expand Up @@ -1304,7 +1304,7 @@ macro_rules! uint_impl {
#[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`
Expand Down Expand Up @@ -1367,7 +1367,7 @@ macro_rules! uint_impl {
#[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
Expand Down Expand Up @@ -1465,7 +1465,7 @@ macro_rules! uint_impl {
#[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
Expand Down
Loading