feat: ranged byte[] compress/decompress overloads#58
Closed
dfa1 wants to merge 1 commit into
Closed
Conversation
Add (offset, length) sub-range overloads so callers holding a payload inside a larger buffer can compress/decompress it without copying the sub-range out first: - compress(byte[] src, int offset, int length) - compress(byte[] src, int offset, int length, int level) - decompress(byte[] compressed, int offset, int length, int maxSize) The range is validated with Objects.checkFromIndexSize before touching native memory. Whole-array overloads now delegate to the ranged ones, keeping the null-check semantics identical. A ranged copyIn helper backs the native copy. Closes #55 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
Closing: declining the ranged byte[] overloads. A byte[] lives on the JVM heap, so these always copy heap→native — they can't be zero-copy, only convenient. Widening the byte[] surface invites callers to reach for it on hot paths expecting efficiency (a footgun). Zero-copy stays the MemorySegment / direct-ByteBuffer path; the byte[] surface stays minimal. |
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
Adds
(offset, length)sub-range overloads toio.github.dfa1.zstd.Zstdso callers holding a payload inside a larger buffer can compress/decompress it without copying the sub-range out first:How
Objects.checkFromIndexSize(offset, length, src.length)(after a null-check) before any native memory is touched — throwsIndexOutOfBoundsExceptionwith a clear message, handling negatives/overflow.copyIn(Arena, byte[], int offset, int length)backs the native copy; the existing whole-arraycopyIndelegates to it.compress(src, level)->compress(src, 0, src.length, level), etc.), keeping the existing null-check semantics identical and avoiding duplication.(long) lengthis passed as the nativesrcSize.Tests
New
RangedOverloadsnested class inZstdTest: ranged round-trips across the shared payload spread, ranged-equals-extracted-copy proof across all levels, full-range equals whole-array overload, empty range, embedded-frame ranged decompress, and negatives (negative offset/length, range past end, null src) asserting the thrown type.Verification
./mvnw -pl zstd test— green (285 tests)../mvnw javadoc:javadoc -pl zstd— zero output (failOnWarnings on)../mvnw -pl zstd validate(checkstyle) — clean.Closes #55
🤖 Generated with Claude Code