Skip to content

feat: digested-dictionary factories + dictionary-lifetime docs#33

Merged
dfa1 merged 1 commit into
mainfrom
feat/dict-ergonomics
Jun 27, 2026
Merged

feat: digested-dictionary factories + dictionary-lifetime docs#33
dfa1 merged 1 commit into
mainfrom
feat/dict-ergonomics

Conversation

@dfa1

@dfa1 dfa1 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What

Improves the dictionary API ergonomics that a leaky usage snippet exposed.

Factories (new)

ZstdDictionary.compressDict(int) / compressDict() / decompressDict():

try (ZstdCompressDict cdict = dict.compressDict(19)) { ... }   // was: new ZstdCompressDict(dict, 19)

Reads fluently and signals the result is AutoCloseable.

Docs

docs/how-to.md now uses the factories and states the lifetime rule the bad snippet missed:

  • refDictionary borrows — the digested dict isn't tied to the context and must be closed separately.
  • one context → use loadDictionary (context-owned, freed for you).
  • a never-closed ZstdCompressDict is 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

…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>
@dfa1 dfa1 merged commit 367556e into main Jun 27, 2026
1 check passed
@dfa1 dfa1 deleted the feat/dict-ergonomics branch June 27, 2026 16:16
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