This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 04d0ebea7 `unsafe` improvements (#6551)
04d0ebea7 is described below
commit 04d0ebea717d3563a2065cb1469372f5211f6bb3
Author: Devin Jeanpierre <[email protected]>
AuthorDate: Mon Oct 21 00:55:27 2024 -0700
`unsafe` improvements (#6551)
* Remove unnecessary use of `unsafe` by reusing existing code
* Remove unnecessary use of MaybeUninit
---
arrow-buffer/src/builder/offset.rs | 7 +++++--
arrow-buffer/src/util/bit_mask.rs | 8 ++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/arrow-buffer/src/builder/offset.rs
b/arrow-buffer/src/builder/offset.rs
index 1ef0e3170..a51ca5f01 100644
--- a/arrow-buffer/src/builder/offset.rs
+++ b/arrow-buffer/src/builder/offset.rs
@@ -70,8 +70,11 @@ impl<O: ArrowNativeType> OffsetBufferBuilder<O> {
///
/// Panics if offsets overflow `O`
pub fn finish_cloned(&self) -> OffsetBuffer<O> {
- O::from_usize(self.last_offset).expect("overflow");
- unsafe { OffsetBuffer::new_unchecked(self.offsets.clone().into()) }
+ let cloned = Self {
+ offsets: self.offsets.clone(),
+ last_offset: self.last_offset,
+ };
+ cloned.finish()
}
}
diff --git a/arrow-buffer/src/util/bit_mask.rs
b/arrow-buffer/src/util/bit_mask.rs
index d4c2fa474..83c395db8 100644
--- a/arrow-buffer/src/util/bit_mask.rs
+++ b/arrow-buffer/src/util/bit_mask.rs
@@ -127,16 +127,16 @@ unsafe fn set_upto_64bits(
}
/// # Safety
-/// The caller must ensure all arguments are within the valid range.
+/// The caller must ensure `data` has `offset..(offset + 8)` range, and `count
<= 8`.
#[inline]
unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 {
debug_assert!(count <= 8);
- let mut tmp = std::mem::MaybeUninit::<u64>::new(0);
+ let mut tmp: u64 = 0;
let src = data.as_ptr().add(offset);
unsafe {
- std::ptr::copy_nonoverlapping(src, tmp.as_mut_ptr() as *mut u8, count);
- tmp.assume_init()
+ std::ptr::copy_nonoverlapping(src, &mut tmp as *mut _ as *mut u8,
count);
}
+ tmp
}
/// # Safety