Class RetainedConfigSet

java.lang.Object
org.antlr.v4.runtime.atn.RetainedConfigSet

final class RetainedConfigSet extends Object
Lazily allocated, capacity-preserving scratch 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 Details

  • Constructor Details

  • Method Details

    • obtain

      @NotNull ATNConfigSet obtain(int sourceSize)
      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 (see ATNConfigSet.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 if obtain(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 first obtain(int), else null. Same-package tests may observe identity and emptiness.