refactor(reader): Array.segmentIfPresent() replaces ArraySegments.trySegment#77
Merged
Conversation
…IfPresent() The deprecated ArraySegments class held a single static probe (trySegment) behind the dict zip-bomb guard. Replace it with an instance method on the Array interface: default Optional<MemorySegment> segmentIfPresent() // empty by default overridden by the segment-backed types to return their existing buffer, and by MaskedArray to delegate to its inner data. ScanIterator calls codes.segmentIfPresent(). Because each override now reads its own field directly, the package-private accessors that existed only to feed the central switch are gone: Materialized*.buffer() (8) and GenericArray.buffer(int). bytesSegment() (5 decoder callers) and the LazyDecimalArray buf record component stay; their overrides reuse them. ArraySegments is deleted. Naming: segmentIfPresent() reads as the non-allocating counterpart to materialize(arena) — returns the buffer only when one already exists, empty otherwise (no allocate/decode). core 223, reader 638 green; full reactor compiles; javadoc + checkstyle clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ce24d6d to
a38b191
Compare
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.
What
Removes the deprecated
ArraySegmentsclass. Its sole method — the non-allocatingtrySegmentprobe behind the dictionary zip-bomb guard — becomes an instance method on theArrayinterface:Materialized*,VarBinArray,GenericArray,LazyDecimalArray) override it to return their existing buffer;MaskedArraydelegates to its inner data.ScanIteratorcallscodes.segmentIfPresent().ArraySegmentsis deleted (it was@Deprecated(forRemoval=true)).Accessor cleanup
Because each override reads its own field directly, the package-private accessors that existed only to feed the old central switch are removed:
Materialized*.buffer()×8GenericArray.buffer(int)bytesSegment()stays (5 decoder callers) andLazyDecimalArray.bufstays (record component); their overrides just reuse them.Naming
segmentIfPresent()reads as the non-allocating counterpart tomaterialize(arena): returns the backing buffer only when one already exists, empty otherwise — never allocates or decodes. (Replaces the cryptictrySegment.)Behaviour
Unchanged — same probe semantics (unwrap masked → inner; empty for lazy/composite). The zip-bomb guard still works identically.
Tests
core 223, reader 638 green; full reactor compiles; javadoc + checkstyle clean.
🤖 Generated with Claude Code