Repository navigation
Add ArrayData::sliced to avoid allocations when slicing owned ArrayData - #11433
Merged
Merged
Conversation
Generated-by: OpenAI Codex
alamb
approved these changes
Oct 8, 2026
alamb
left a comment
Contributor
There was a problem hiding this comment.
Thank you @memosmorgan -- this looks good to me
| /// | ||
| /// Panics if `offset + length` overflows or is greater than `self.len()`. | ||
| pub fn slice(&self, offset: usize, length: usize) -> ArrayData { | ||
| self.clone().sliced(offset, length) |
Contributor
There was a problem hiding this comment.
it is pretty minor but this could call slice_in_place and skip a function call in sliced
Contributor
There was a problem hiding this comment.
We can always do this as a follow on PR too
ArrayData::sliced to avoid allocations when slicing owned ArrayData
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
ArrayData::slice()on owned ArrayData #9140Replaces #11432.
Rationale for this change
Owned
ArrayDatacan be sliced without allocating new buffer or child vectors.AI assistance: OpenAI Codex generated the implementation and tests, ran the local checks, and reviewed the diff.
What changes are included in this PR?
Add
ArrayData::sliced, which consumes the array and reuses its allocations, including nested struct children. Use it when converting owned data toStructArray.Are these changes tested?
Regression tests cover equivalence with borrowed slicing, offsets, nested structs, lists, nulls, empty/end slices, and bounds. They also check that vector allocations are retained.
A local release-mode allocation counter measured the following for 1,024-element inputs sliced at offset 1 for 512 elements, excluding input construction:
sliceallocationsslicedallocationsAre there any significant user-facing changes?
No breaking changes. Borrowed
sliceretains its existing behavior.