From 735218b990fc0a19a3ec8cdec09fb847bc8e8efa Mon Sep 17 00:00:00 2001 From: Jorge Leitao Date: Tue, 12 Jul 2022 07:10:27 -0700 Subject: [PATCH] Removed un-needed indirection (#1153) --- src/buffer/mod.rs | 2 +- src/ffi/array.rs | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 10f62488707..55dca4e61f2 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -4,6 +4,6 @@ mod immutable; use crate::ffi::InternalArrowArray; -pub(crate) type Bytes = foreign_vec::ForeignVec, T>; +pub(crate) type Bytes = foreign_vec::ForeignVec; pub use immutable::Buffer; diff --git a/src/ffi/array.rs b/src/ffi/array.rs index fd45ce9652c..099424c6f9f 100644 --- a/src/ffi/array.rs +++ b/src/ffi/array.rs @@ -179,7 +179,7 @@ impl ArrowArray { unsafe fn create_buffer( array: &ArrowArray, data_type: &DataType, - owner: Box, + owner: InternalArrowArray, index: usize, ) -> Result> { if array.buffers.is_null() { @@ -210,7 +210,7 @@ unsafe fn create_buffer( /// This function assumes that `ceil(self.length * bits, 8)` is the size of the buffer unsafe fn create_bitmap( array: &ArrowArray, - owner: Box, + owner: InternalArrowArray, index: usize, ) -> Result { if array.buffers.is_null() { @@ -311,7 +311,7 @@ fn buffer_len(array: &ArrowArray, data_type: &DataType, i: usize) -> Result, + parent: InternalArrowArray, index: usize, ) -> Result> { let data_type = get_child(field, index)?; @@ -322,27 +322,27 @@ fn create_child( assert!(!arr_ptr.is_null()); let arr_ptr = &*arr_ptr; - Ok(ArrowArrayChild::from_raw(arr_ptr, data_type, parent)) + Ok(ArrowArrayChild::new(arr_ptr, data_type, parent)) } } fn create_dictionary( array: &ArrowArray, data_type: &DataType, - parent: Box, + parent: InternalArrowArray, ) -> Result>> { if let DataType::Dictionary(_, values, _) = data_type { let data_type = values.as_ref().clone(); assert!(!array.dictionary.is_null()); let array = unsafe { &*array.dictionary }; - Ok(Some(ArrowArrayChild::from_raw(array, data_type, parent))) + Ok(Some(ArrowArrayChild::new(array, data_type, parent))) } else { Ok(None) } } pub trait ArrowArrayRef: std::fmt::Debug { - fn owner(&self) -> Box { + fn owner(&self) -> InternalArrowArray { (*self.parent()).clone() } @@ -386,7 +386,7 @@ pub trait ArrowArrayRef: std::fmt::Debug { fn n_buffers(&self) -> usize; - fn parent(&self) -> &Box; + fn parent(&self) -> &InternalArrowArray; fn array(&self) -> &ArrowArray; fn data_type(&self) -> &DataType; } @@ -433,7 +433,7 @@ impl ArrowArrayRef for Box { &self.data_type } - fn parent(&self) -> &Box { + fn parent(&self) -> &InternalArrowArray { self } @@ -450,7 +450,7 @@ impl ArrowArrayRef for Box { pub struct ArrowArrayChild<'a> { array: &'a ArrowArray, data_type: DataType, - parent: Box, + parent: InternalArrowArray, } impl<'a> ArrowArrayRef for ArrowArrayChild<'a> { @@ -459,7 +459,7 @@ impl<'a> ArrowArrayRef for ArrowArrayChild<'a> { &self.data_type } - fn parent(&self) -> &Box { + fn parent(&self) -> &InternalArrowArray { &self.parent } @@ -473,11 +473,7 @@ impl<'a> ArrowArrayRef for ArrowArrayChild<'a> { } impl<'a> ArrowArrayChild<'a> { - fn from_raw( - array: &'a ArrowArray, - data_type: DataType, - parent: Box, - ) -> Self { + fn new(array: &'a ArrowArray, data_type: DataType, parent: InternalArrowArray) -> Self { Self { array, data_type,