tustvold commented on code in PR #5922:
URL: https://github.com/apache/arrow-rs/pull/5922#discussion_r1650032760


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -429,6 +514,40 @@ impl<T: ByteViewType + ?Sized> From<ArrayData> for 
GenericByteViewArray<T> {
     }
 }
 
+impl<FROM, V> From<&GenericByteArray<FROM>> for GenericByteViewArray<V>
+where
+    FROM: ByteArrayType,
+    FROM::Offset: OffsetSizeTrait + ToPrimitive,
+    V: ByteViewType,
+    FROM::Native: PartialEq<V::Native>, // this prevent users to convert 
between byte and string types.
+{
+    fn from(value: &GenericByteArray<FROM>) -> Self {
+        let byte_array = value;
+        let len = byte_array.len();
+        let str_values_buf = byte_array.values().clone();
+        let offsets = byte_array.offsets();
+
+        let mut views_builder = 
GenericByteViewBuilder::<V>::with_capacity(len);
+        let block = views_builder.append_block(str_values_buf);
+        for (i, w) in offsets.windows(2).enumerate() {
+            let offset = w[0].to_u32().unwrap();
+            let end = w[1].to_u32().unwrap();

Review Comment:
   It would be faster to just check that the last offset is `<= u32::MAX` and 
then use unchecked conversions here.
   
   This would also allow removing `ToPrimitive` and just doing `w[0].as_usize() 
as u32` which will make this easier to use in generic contexts



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