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


##########
arrow-buffer/src/buffer/boolean.rs:
##########
@@ -610,6 +610,53 @@ impl BooleanBuffer {
         }
     }
 
+    /// Try to convert self into a [`BooleanBufferBuilder`] without copying.
+    ///
+    /// Reuses the underlying [`Buffer`] allocation if
+    /// 1. it is not shared (no other references to it exist) and
+    /// 2. the bit offset is zero
+    ///
+    /// Returns `Err(self)` if the allocation cannot be reused.
+    ///
+    /// # Example
+    /// ```
+    /// # use arrow_buffer::BooleanBuffer;
+    /// let buffer = BooleanBuffer::from(vec![true, false, true]);
+    /// // The buffer is not shared, so the builder reuses its allocation
+    /// let mut builder = buffer.try_into_builder().expect("buffer was not 
shared");
+    /// builder.append(false);
+    /// assert_eq!(builder.finish(), BooleanBuffer::from(vec![true, false, 
true, false]));
+    ///
+    /// // Conversion fails if the buffer is shared
+    /// let buffer = BooleanBuffer::from(vec![true, false, true]);
+    /// let shared = buffer.clone();
+    /// let buffer = buffer.try_into_builder().expect_err("buffer was shared");
+    /// # assert_eq!(buffer, shared);
+    /// ```
+    pub fn try_into_builder(self) -> Result<BooleanBufferBuilder, Self> {

Review Comment:
   do we still want this new method?



##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -607,10 +607,35 @@ impl BooleanArray {
             return self;
         };
 
-        let mut builder = BooleanBufferBuilder::new(len);
-        builder.append_buffer(&self.values.slice(0, end));
-        builder.append_n(len - end, false);
-        BooleanArray::new(builder.finish(), self.nulls)
+        let bit_offset = self.values.offset();
+        let inner_buf = self.values.into_inner();
+
+        match inner_buf.into_mutable() {

Review Comment:
   only concern now is if our existing unit tests cover both these paths



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