Jefffrey commented on code in PR #10893:
URL: https://github.com/apache/arrow-rs/pull/10893#discussion_r3877296751


##########
arrow-array/src/array/primitive_array.rs:
##########
@@ -1196,15 +1196,31 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
 
 impl<T: ArrowPrimitiveType> From<PrimitiveArray<T>> for ArrayData {
     fn from(array: PrimitiveArray<T>) -> Self {
-        let builder = ArrayDataBuilder::new(array.data_type)
-            .len(array.values.len())
-            .nulls(array.nulls)
-            .buffers(vec![array.values.into_inner()]);
-
-        unsafe { builder.build_unchecked() }
+        let len = array.values.len();
+        primitive_to_array_data(array.data_type, len, 
array.values.into_inner(), array.nulls)
     }
 }
 
+/// Converts the parts of a valid `PrimitiveArray` into [`ArrayData`]
+///
+/// Deliberately not generic over [`ArrowPrimitiveType`]: after extracting the
+/// untyped [`Buffer`] the conversion is identical for all primitive types, so
+/// keeping it non-generic means it is compiled once rather than once per type
+fn primitive_to_array_data(

Review Comment:
   should we just make this an inner function to the from, similar to how 
stdlib does it here?
   
   https://doc.rust-lang.org/nightly/src/std/fs.rs.html#346-355



-- 
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]

Reply via email to