Class RetainedConfigSet
ATNConfigSet for
prediction and lexing hot paths.
Ownership contract (single rule): obtain(int)
always returns an empty writable set (clears on reuse). Callers must
release() in a finally after the edge / closure work so
config-graph references are dropped between uses while list/map capacity is
retained. DFA storage must clone before
release().
PERF: Both obtain(int) and release() may
call ATNConfigSet.clear(). That clear is intentionally cheap when the
buffer is already empty (no full-table Arrays.fill on the merge map)
and only nulls the used list prefix when non-empty — see
ATNConfigSet.clear() and ClearableLongObjectHashMap. The
obtain/release pair therefore does not pay double bulk-zero of the open-
addressed tables on the common path (release empties; obtain is a free
empty clear). Skipping clear on obtain entirely would leave flags/storage
dirty if a caller reused without release; both sides stay defensive.
Package-private: shared by ParserATNSimulator,
LexerATNSimulator, and tests in this package.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) ATNConfigSetbuffer()Underlying buffer after firstobtain(int), elsenull.(package private) ATNConfigSetobtain(int sourceSize) Returns the retained buffer, allocating on first use.(package private) voidrelease()Drops config-graph references held by the buffer; keeps capacity.
-
Field Details
-
ordered
private final boolean ordered -
buffer
-
-
Constructor Details
-
RetainedConfigSet
RetainedConfigSet(boolean ordered) - Parameters:
ordered-trueforOrderedATNConfigSet(lexer),falsefor plainATNConfigSet(parser)
-
-
Method Details
-
obtain
Returns the retained buffer, allocating on first use. Always empty on return (clears when reusing an existing buffer). Clear of an already-empty buffer is O(1) for the merge map (seeATNConfigSet.clear()).- Parameters:
sourceSize- hint for initial capacity (ATNConfigSet.scratchCapacity(int))
-
release
void release()Drops config-graph references held by the buffer; keeps capacity. No-op ifobtain(int)has never been called. When the buffer is already empty, clear is O(1) for the merge map and does not bulk-zero backing arrays. -
buffer
Underlying buffer after firstobtain(int), elsenull. Same-package tests may observe identity and emptiness.
-