Skip to content

refactor(reader): Array.segmentIfPresent() replaces ArraySegments.trySegment#77

Merged
dfa1 merged 1 commit into
mainfrom
worktree-trysegment-cleanup
Jun 20, 2026
Merged

refactor(reader): Array.segmentIfPresent() replaces ArraySegments.trySegment#77
dfa1 merged 1 commit into
mainfrom
worktree-trysegment-cleanup

Conversation

@dfa1

@dfa1 dfa1 commented Jun 20, 2026

Copy link
Copy Markdown
Owner

What

Removes the deprecated ArraySegments class. Its sole method — the non-allocating trySegment probe behind the dictionary zip-bomb guard — becomes an instance method on the Array interface:

default Optional<MemorySegment> segmentIfPresent() { return Optional.empty(); }
  • Segment-backed types (Materialized*, VarBinArray, GenericArray, LazyDecimalArray) override it to return their existing buffer; MaskedArray delegates to its inner data.
  • ScanIterator calls codes.segmentIfPresent().
  • ArraySegments is 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() ×8
  • GenericArray.buffer(int)

bytesSegment() stays (5 decoder callers) and LazyDecimalArray.buf stays (record component); their overrides just reuse them.

Naming

segmentIfPresent() reads as the non-allocating counterpart to materialize(arena): returns the backing buffer only when one already exists, empty otherwise — never allocates or decodes. (Replaces the cryptic trySegment.)

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

…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>
@dfa1 dfa1 force-pushed the worktree-trysegment-cleanup branch from ce24d6d to a38b191 Compare June 20, 2026 05:24
@dfa1 dfa1 merged commit 32a35e0 into main Jun 20, 2026
6 checks passed
@dfa1 dfa1 deleted the worktree-trysegment-cleanup branch June 20, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant