Skip to content

Commit 4cf3d66

Browse files
committed
use div_ceil instead of manual logic
1 parent af2315f commit 4cf3d66

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

core/src/slice/sort/stable/drift.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn merge_tree_scale_factor(n: usize) -> u64 {
158158
panic!("Platform not supported");
159159
}
160160

161-
((1 << 62) + n as u64 - 1) / n as u64
161+
(1u64 << 62).div_ceil(n as u64)
162162
}
163163

164164
// Note: merge_tree_depth output is < 64 when left < right as f*x and f*y must
@@ -182,7 +182,7 @@ fn sqrt_approx(n: usize) -> usize {
182182
// Finally we note that the exponentiation / division can be done directly
183183
// with shifts. We OR with 1 to avoid zero-checks in the integer log.
184184
let ilog = (n | 1).ilog2();
185-
let shift = (1 + ilog) / 2;
185+
let shift = ilog.div_ceil(2);
186186
((1 << shift) + (n >> shift)) / 2
187187
}
188188

core/src/str/iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> Iterator for Chars<'a> {
102102
// `(len + 3)` can't overflow, because we know that the `slice::Iter`
103103
// belongs to a slice in memory which has a maximum length of
104104
// `isize::MAX` (that's well below `usize::MAX`).
105-
((len + 3) / 4, Some(len))
105+
(len.div_ceil(4), Some(len))
106106
}
107107

108108
#[inline]
@@ -1532,11 +1532,11 @@ impl<'a> Iterator for EncodeUtf16<'a> {
15321532
// belongs to a slice in memory which has a maximum length of
15331533
// `isize::MAX` (that's well below `usize::MAX`)
15341534
if self.extra == 0 {
1535-
((len + 2) / 3, Some(len))
1535+
(len.div_ceil(3), Some(len))
15361536
} else {
15371537
// We're in the middle of a surrogate pair, so add the remaining
15381538
// surrogate to the bounds.
1539-
((len + 2) / 3 + 1, Some(len + 1))
1539+
(len.div_ceil(3) + 1, Some(len + 1))
15401540
}
15411541
}
15421542
}

portable-simd/crates/core_simd/src/lane_count.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct LaneCount<const N: usize>;
88

99
impl<const N: usize> LaneCount<N> {
1010
/// The number of bytes in a bitmask with this many lanes.
11-
pub const BITMASK_LEN: usize = (N + 7) / 8;
11+
pub const BITMASK_LEN: usize = N.div_ceil(8);
1212
}
1313

1414
/// Statically guarantees that a lane count is marked as supported.

0 commit comments

Comments
 (0)