Dandandan commented on a change in pull request #9076:
URL: https://github.com/apache/arrow/pull/9076#discussion_r550909022
##########
File path: rust/arrow/src/buffer.rs
##########
@@ -852,17 +870,34 @@ impl MutableBuffer {
}
}
- /// Extends the buffer from a byte slice, incrementing its capacity if
needed.
+ /// Extends the buffer from a slice, increasing its capacity if needed.
+ #[inline]
+ pub fn extend_from_slice<T: ToByteSlice>(&mut self, items: &[T]) {
+ let additional = items.len() * std::mem::size_of::<T>();
+ let new_len = self.len + additional;
+ if new_len > self.capacity {
+ self.reserve(additional);
+ }
+ unsafe {
+ let dst = self.data.as_ptr().add(self.len) as *mut T;
+ let src = items.as_ptr() as *const T;
+ std::ptr::copy_nonoverlapping(src, dst, items.len())
+ }
+ self.len = new_len;
+ }
+
+ /// Extends the buffer with a new item, increasing its capacity if needed.
#[inline]
- pub fn extend_from_slice(&mut self, bytes: &[u8]) {
- let additional = bytes.len();
- if self.len + additional > self.capacity() {
+ pub fn push<T: ToByteSlice>(&mut self, item: &T) {
Review comment:
Could this be `item: T` too?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]