This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new cdf72ddc49 Use rust builtins (#7358)
cdf72ddc49 is described below
commit cdf72ddc494837b351922f7cc26c008410468f9e
Author: Vrishabh <[email protected]>
AuthorDate: Thu Apr 3 20:31:51 2025 +0530
Use rust builtins (#7358)
---
arrow-buffer/src/util/bit_util.rs | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/arrow-buffer/src/util/bit_util.rs
b/arrow-buffer/src/util/bit_util.rs
index f39cb69c31..c297321bdc 100644
--- a/arrow-buffer/src/util/bit_util.rs
+++ b/arrow-buffer/src/util/bit_util.rs
@@ -20,7 +20,8 @@
/// Returns the nearest number that is `>=` than `num` and is a multiple of 64
#[inline]
pub fn round_upto_multiple_of_64(num: usize) -> usize {
- round_upto_power_of_2(num, 64)
+ num.checked_next_multiple_of(64)
+ .expect("failed to round upto multiple of 64")
}
/// 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) {
/// Returns the ceil of `value`/`divisor`
#[inline]
pub fn ceil(value: usize, divisor: usize) -> usize {
- // Rewrite as `value.div_ceil(&divisor)` after
- // https://github.com/rust-lang/rust/issues/88581 is merged.
- value / divisor + (0 != value % divisor) as usize
+ value.div_ceil(divisor)
}
#[cfg(test)]
@@ -109,6 +108,12 @@ mod tests {
assert_eq!(192, round_upto_multiple_of_64(129));
}
+ #[test]
+ #[should_panic(expected = "failed to round upto multiple of 64")]
+ fn test_round_upto_multiple_of_64_panic() {
+ let _ = round_upto_multiple_of_64(usize::MAX);
+ }
+
#[test]
#[should_panic(expected = "failed to round to next highest power of 2")]
fn test_round_upto_panic() {