mapleFU commented on code in PR #8694:
URL: https://github.com/apache/arrow-rs/pull/8694#discussion_r2476188161


##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -512,18 +512,71 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
             };
         }
 
-        // 3) Allocate exactly capacity for all non-inline data
-        let mut data_buf = Vec::with_capacity(total_large);
+        struct GcCopyGroup {
+            total_buffer_bytes: usize,
+            total_len: usize,
+        }
+
+        let mut groups = vec![];
+        let one_group = [GcCopyGroup {
+            total_buffer_bytes: total_large,
+            total_len: len,
+        }];
+        let gc_copy_groups = if total_large > i32::MAX as usize {
+            // Slow-path: need to split into multiple copy groups
+            let mut current_length = 0;
+            let mut current_elements = 0;
+
+            for view in self.views() {
+                let len = *view as u32;
+                if len > MAX_INLINE_VIEW_LEN {
+                    if current_length + len > i32::MAX as u32 {
+                        // Start a new group
+                        groups.push(GcCopyGroup {
+                            total_buffer_bytes: current_length as usize,
+                            total_len: current_elements,
+                        });
+                        current_length = 0;
+                        current_elements = 0;
+                    }
+                    current_length += len;
+                    current_elements += 1;
+                }
+            }
+            if current_elements != 0 {
+                groups.push(GcCopyGroup {
+                    total_buffer_bytes: current_length as usize,
+                    total_len: current_elements,
+                });
+            }
+            &groups
+        } else {
+            one_group.as_slice()

Review Comment:
   I've add a `one_group` for gc-copy-group in stack, hopefully this avoids 
allocation
   
   ```rust
   let one_group = [GcCopyGroup {
               total_buffer_bytes: total_large,
               total_len: len,
           }];
   ```



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