From 1865e27bdb0e746fd4121d94e6bb70f78f6755ae Mon Sep 17 00:00:00 2001 From: rich-T-kid Date: Sun, 26 Jul 2026 10:56:50 -0400 Subject: [PATCH] avoid re-allocation if buffer is not shared --- arrow-array/src/array/boolean_array.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/arrow-array/src/array/boolean_array.rs b/arrow-array/src/array/boolean_array.rs index 9245f5b33700..bcb4faa86e70 100644 --- a/arrow-array/src/array/boolean_array.rs +++ b/arrow-array/src/array/boolean_array.rs @@ -593,10 +593,22 @@ 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 mut_buffer_result = self.values.into_inner().into_mutable(); + match mut_buffer_result { + Ok(mut mutable_buffer) => { + for i in end..len { + bit_util::unset_bit(mutable_buffer.as_slice_mut(), i); + } + let boolean_buf = BooleanBuffer::new(mutable_buffer.into(), 0, len); + BooleanArray::new(boolean_buf, self.nulls) + } + Err(buf) => { + let mut builder = BooleanBufferBuilder::new(len); + builder.append_buffer(&BooleanBuffer::new(buf, 0, end)); + builder.append_n(len - end, false); + BooleanArray::new(builder.finish(), self.nulls) + } + } } /// Deconstruct this array into its constituent parts