tustvold commented on code in PR #6901:
URL: https://github.com/apache/arrow-rs/pull/6901#discussion_r1890547927
##########
arrow-buffer/src/buffer/scalar.rs:
##########
@@ -64,14 +64,41 @@ impl<T: ArrowNativeType> ScalarBuffer<T> {
///
/// * `offset` or `len` would result in overflow
/// * `buffer` is not aligned to a multiple of `std::mem::align_of::<T>`
- /// * `bytes` is not large enough for the requested slice
+ /// * `buffer` is not large enough for the requested slice
pub fn new(buffer: Buffer, offset: usize, len: usize) -> Self {
let size = std::mem::size_of::<T>();
let byte_offset = offset.checked_mul(size).expect("offset overflow");
let byte_len = len.checked_mul(size).expect("length overflow");
buffer.slice_with_length(byte_offset, byte_len).into()
}
+ /// Create a new [`ScalarBuffer`] from a [`Buffer`], and an `offset`
+ /// and `length` in units of `T`
+ ///
+ /// # Safety
+ ///
+ /// This method will be safe UNLESS any of the following:
+ ///
+ /// * `offset` or `len` would result in overflow
+ /// * `buffer` is not aligned to a multiple of `std::mem::align_of::<T>`
+ /// * `buffer` is not large enough for the requested slice
+ pub unsafe fn new_unchecked(buffer: Buffer, offset: usize, len: usize) ->
Self {
+ let size = std::mem::size_of::<T>();
+ let byte_offset = offset * size;
+ let byte_len = len * size;
+ unsafe {
+ buffer
+ .slice_with_length_unchecked(byte_offset, byte_len)
+ .into()
+ }
+ }
+
+ /// The length of the scalar buffer, in units of `T`.
+ #[inline]
+ pub fn len_in_elements(&self) -> usize {
Review Comment:
The deref impl already means that `x.len()` returns this
--
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]