Skip to content

Commit cdf72dd

Browse files
authored
Use rust builtins (#7358)
1 parent ae524e7 commit cdf72dd

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

arrow-buffer/src/util/bit_util.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
/// Returns the nearest number that is `>=` than `num` and is a multiple of 64
2121
#[inline]
2222
pub fn round_upto_multiple_of_64(num: usize) -> usize {
23-
round_upto_power_of_2(num, 64)
23+
num.checked_next_multiple_of(64)
24+
.expect("failed to round upto multiple of 64")
2425
}
2526

2627
/// Returns the nearest multiple of `factor` that is `>=` than `num`. Here `factor` must
@@ -86,9 +87,7 @@ pub unsafe fn unset_bit_raw(data: *mut u8, i: usize) {
8687
/// Returns the ceil of `value`/`divisor`
8788
#[inline]
8889
pub fn ceil(value: usize, divisor: usize) -> usize {
89-
// Rewrite as `value.div_ceil(&divisor)` after
90-
// https://github.com/rust-lang/rust/issues/88581 is merged.
91-
value / divisor + (0 != value % divisor) as usize
90+
value.div_ceil(divisor)
9291
}
9392

9493
#[cfg(test)]
@@ -109,6 +108,12 @@ mod tests {
109108
assert_eq!(192, round_upto_multiple_of_64(129));
110109
}
111110

111+
#[test]
112+
#[should_panic(expected = "failed to round upto multiple of 64")]
113+
fn test_round_upto_multiple_of_64_panic() {
114+
let _ = round_upto_multiple_of_64(usize::MAX);
115+
}
116+
112117
#[test]
113118
#[should_panic(expected = "failed to round to next highest power of 2")]
114119
fn test_round_upto_panic() {

0 commit comments

Comments
 (0)