alamb opened a new pull request, #10397: URL: https://github.com/apache/arrow-rs/pull/10397
# Which issue does this PR close? - Part of #6430 # Rationale for this change Code that owns a `BooleanBuffer` and wants to keep appending to / mutating it currently has to copy the bits into a new `BooleanBufferBuilder`, even when the underlying allocation is uniquely owned and could be reused directly. This PR adds "convert into a builder when not shared" APIs for `BooleanBuffer`, following the model of `Buffer::into_mutable` and `PrimitiveArray::into_builder`. An immediate motivating use case is the parquet filter mask accumulator work (#TODO), which today copies a `BooleanBuffer` into a fresh builder to combine masks. # What changes are included in this PR? Two new APIs on `BooleanBuffer`: 1. `try_into_builder(self) -> Result<BooleanBufferBuilder, Self>`: reuses the allocation (no copy) when the buffer's bit offset is zero and the underlying `Buffer` is uniquely owned; otherwise returns `Err(self)` 2. `into_builder_or_clone(self) -> BooleanBufferBuilder`: convenience wrapper that always succeeds, copying the bits when the allocation cannot be reused Also updates `BooleanArray::take_n_true` to use the new API, so it reuses the values allocation instead of unconditionally copying (a survey of the repo found the other builder-copy sites operate on borrowed buffers or need to preserve non-zero bit offsets, so they cannot use a consuming API). # Naming / follow up I would like `try_into_builder` to become the standard name for this pattern: the `try_` prefix plus `Result` follows Rust conventions, unlike the existing `PrimitiveArray::into_builder` which is fallible despite its name. If this API looks good, a follow on PR will propose renaming `PrimitiveArray::into_builder` to `try_into_builder` (with a deprecated alias) and adding the corresponding `into_builder_or_clone`. # Are these changes tested? Yes: new unit tests cover allocation reuse (pointer equality), the shared-buffer and non-zero-offset failure paths, padding-bit clearing, and the copy fallback; both new APIs also have doc examples. # Are there any user-facing changes? Two new public methods on `BooleanBuffer`. No changes to existing APIs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
