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


##########
arrow-string/src/length.rs:
##########
@@ -137,6 +138,22 @@ pub fn bit_length(array: &dyn Array) -> Result<ArrayRef, 
ArrowError> {
             let list = array.as_string::<i64>();
             Ok(bit_length_impl::<Int64Type>(list.offsets(), list.nulls()))
         }
+        DataType::Utf8View => {
+            let list = array.as_string_view();
+            let values = (0..list.len())
+                .map(|i| {
+                    if list.is_valid(i) {
+                        list.views()[i] as u32 * 8
+                    } else {
+                        0
+                    }
+                })
+                .collect::<Vec<u32>>();
+            Ok(Arc::new(UInt32Array::new(
+                values.into(),

Review Comment:
   ```suggestion
               let values = list.views().iter().map(|view| (view as 
i32).wrapping_mul(8)).collect();
               Ok(Arc::new(UInt32Array::new(
                   values,
   ```
   
   As we're doing infallible wrapping arithmetic, we can just compute this for 
everything, this will vectorize better, and the null mask is preserved below



##########
arrow-string/src/length.rs:
##########
@@ -137,6 +138,22 @@ pub fn bit_length(array: &dyn Array) -> Result<ArrayRef, 
ArrowError> {
             let list = array.as_string::<i64>();
             Ok(bit_length_impl::<Int64Type>(list.offsets(), list.nulls()))
         }
+        DataType::Utf8View => {
+            let list = array.as_string_view();
+            let values = (0..list.len())
+                .map(|i| {
+                    if list.is_valid(i) {
+                        list.views()[i] as u32 * 8
+                    } else {
+                        0
+                    }
+                })
+                .collect::<Vec<u32>>();
+            Ok(Arc::new(UInt32Array::new(
+                values.into(),

Review Comment:
   ```suggestion
               let values = list.views().iter().map(|view| (view as 
i32).wrapping_mul(8)).collect();
               Ok(Arc::new(Int32Array::new(
                   values,
   ```
   
   As we're doing infallible wrapping arithmetic, we can just compute this for 
everything, this will vectorize better, and the null mask is preserved below



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