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