From ef2864fe15d2c856c05eae70693d68eb2ae00fa8 Mon Sep 17 00:00:00 2001 From: Kazuyuki Tanimura Date: Wed, 4 Sep 2024 15:31:48 -0700 Subject: [PATCH] address review comments --- arrow-buffer/src/util/bit_mask.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arrow-buffer/src/util/bit_mask.rs b/arrow-buffer/src/util/bit_mask.rs index cc827eb5e939..44871fb5004d 100644 --- a/arrow-buffer/src/util/bit_mask.rs +++ b/arrow-buffer/src/util/bit_mask.rs @@ -100,10 +100,12 @@ fn set_upto_64bits( } else { let len = std::cmp::min(len, 64 - std::cmp::max(read_shift, write_shift)); let bytes = ceil(len + read_shift, 8); - // SAFETY: chunk gets masked, so it is safe - let chunk = unsafe { read_bytes_to_u64(data, read_byte, bytes) }; let mask = u64::MAX >> (64 - len); - let chunk = (chunk >> read_shift) & mask; + // SAFETY: chunk gets masked, so it is safe + let chunk = unsafe { + let chunk = read_bytes_to_u64(data, read_byte, bytes); + (chunk >> read_shift) & mask + }; let chunk = chunk << write_shift; let null_count = len - chunk.count_ones() as usize; let bytes = ceil(len + write_shift, 8); @@ -119,7 +121,6 @@ fn set_upto_64bits( /// The caller must ensure all arguments are within the valid range. /// The caller must be aware `8 - count` bytes in the returned value are uninitialized. #[inline] -#[cfg(not(miri))] unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 { debug_assert!(count <= 8); let mut tmp = std::mem::MaybeUninit::::uninit(); @@ -131,13 +132,6 @@ unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 { } } -#[cfg(miri)] -unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 { - let mut arr = [0u8; 8]; - arr[0..count].copy_from_slice(&data[offset..(offset + count)]); - u64::from_le_bytes(arr) -} - #[inline] fn write_u64_bytes(data: &mut [u8], offset: usize, chunk: u64) { // SAFETY: the caller must ensure `data` has `offset..(offset + 8)` range