tustvold commented on code in PR #3756:
URL: https://github.com/apache/arrow-rs/pull/3756#discussion_r1118800573
##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -69,6 +71,21 @@ impl Buffer {
}
}
+ /// Create a [`Buffer`] from the provided `Vec` without copying
+ #[inline]
+ pub fn from_vec<T: ArrowNativeType>(vec: Vec<T>) -> Self {
+ // Safety
+ // Vec::as_ptr guaranteed to not be null and ArrowNativeType are
trivially transmutable
+ let ptr = unsafe { NonNull::new_unchecked(vec.as_ptr() as _) };
+ let len = vec.len() * std::mem::size_of::<T>();
+ // Safety
+ // Layout guaranteed to be valid
+ let layout = unsafe {
Layout::array::<T>(vec.capacity()).unwrap_unchecked() };
Review Comment:
> Is there a reason to use unwrap_unchecked here
This is a clone of
[`Vec::current_memory`](https://github.com/rust-lang/rust/blob/ccce98535bd51687554be8a209b3a529ef84f7e1/library/alloc/src/raw_vec.rs#L246),
I will add a link
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]