Skip to content

Commit c3b76dc

Browse files
alambDandandan
authored andcommitted
Minor: try and avoid an allocation creating GenericByteViewArray from ArrayData (apache#9156)
# Which issue does this PR close? - part of apache#9061 - follow on apache#9114 # Rationale for this change @scovich noted in apache#9114 (comment) that calling `Vec::remove` does an extra copy and that `Vec::from` doesn't actually reuse the allocation the way I thought it did # What changes are included in this PR? Build the Arc for buffers directly # Are these changes tested? BY existing tests # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. -->
1 parent 9f43539 commit c3b76dc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

arrow-array/src/array/byte_view_array.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,16 @@ impl<'a, T: ByteViewType + ?Sized> IntoIterator for &'a GenericByteViewArray<T>
988988

989989
impl<T: ByteViewType + ?Sized> From<ArrayData> for GenericByteViewArray<T> {
990990
fn from(data: ArrayData) -> Self {
991-
let (_data_type, len, nulls, offset, mut buffers, _child_data) = data.into_parts();
992-
let views = buffers.remove(0); // need to maintain order of remaining buffers
993-
let buffers = Arc::from(buffers);
994-
let views = ScalarBuffer::new(views, offset, len);
991+
let (_data_type, len, nulls, offset, buffers, _child_data) = data.into_parts();
992+
993+
let mut buffers = buffers.into_iter();
994+
// first buffer is views, remaining are data buffers
995+
let views = ScalarBuffer::new(buffers.next().unwrap(), offset, len);
996+
995997
Self {
996998
data_type: T::DATA_TYPE,
997999
views,
998-
buffers,
1000+
buffers: Arc::from_iter(buffers),
9991001
nulls,
10001002
phantom: Default::default(),
10011003
}

0 commit comments

Comments
 (0)