Skip to content

Commit bae1512

Browse files
committed
Avoid manual saturating arithmetic
1 parent 3397168 commit bae1512

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/size_hint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub type SizeHint = (usize, Option<usize>);
1010
/// Add **SizeHint** correctly.
1111
#[inline]
1212
pub fn add(a: SizeHint, b: SizeHint) -> SizeHint {
13-
let min = a.0.checked_add(b.0).unwrap_or(usize::MAX);
13+
let min = a.0.saturating_add(b.0);
1414
let max = match (a.1, b.1) {
1515
(Some(x), Some(y)) => x.checked_add(y),
1616
_ => None,
@@ -56,7 +56,7 @@ pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
5656
/// ```
5757
#[inline]
5858
pub fn mul(a: SizeHint, b: SizeHint) -> SizeHint {
59-
let low = a.0.checked_mul(b.0).unwrap_or(usize::MAX);
59+
let low = a.0.saturating_mul(b.0);
6060
let hi = match (a.1, b.1) {
6161
(Some(x), Some(y)) => x.checked_mul(y),
6262
(Some(0), None) | (None, Some(0)) => Some(0),

0 commit comments

Comments
 (0)