feat: digested-dictionary factories + dictionary-lifetime docs#33
Merged
Conversation
…in docs Adds ZstdDictionary.compressDict(int) / compressDict() / decompressDict() so callers can write dict.compressDict(19) instead of new ZstdCompressDict(dict, 19). The factory names read fluently and signal that the result is AutoCloseable and must be closed. Updates docs/how-to.md to use the factories and to spell out the lifetime rule that the leaky idiom missed: refDictionary only *borrows* a digested dictionary, so it must be closed separately; a single context should use loadDictionary, which the context digests, owns, and frees — a stray ZstdCompressDict that is never closed is a native-memory leak. Deliberately did not add an owning refDictionary(ZstdDictionary, int) overload: loadDictionary already provides context-owned, leak-free dictionary handling for the single-context case, so the overload would only duplicate it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Improves the dictionary API ergonomics that a leaky usage snippet exposed.
Factories (new)
ZstdDictionary.compressDict(int)/compressDict()/decompressDict():Reads fluently and signals the result is
AutoCloseable.Docs
docs/how-to.mdnow uses the factories and states the lifetime rule the bad snippet missed:refDictionaryborrows — the digested dict isn't tied to the context and must be closed separately.loadDictionary(context-owned, freed for you).ZstdCompressDictis a native-memory leak.What I deliberately did not do
An owning
refDictionary(ZstdDictionary, int)overload was considered and dropped:loadDictionary(ZstdDictionary)already digests into the context and frees it on close, so an owning overload would only duplicate existing, leak-free behaviour. Better to steer with docs + the factory than to grow the surface.Tests
New
ZstdDictionaryTest.Factories(level fixed/default, id matches, round-trip). 232 tests green, checkstyle + javadoc clean.🤖 Generated with Claude Code