cheatah
Class

parsers::json::Parser

A reusable parser that owns reusable node/member POOLS.

Parser::parse() builds a Document whose arrays/objects are VIEWS (ArrayView/ObjectView) into these pools — zero per-container heap allocation. Reusing ONE Parser across many parses amortizes the pool allocation/page-faults to ~0 after warm-up (the reusable-parser model), which is the whole point of option B.

LIFETIME: the returned Document VIEWS this Parser's pools, so it is valid only until the next parse() on this Parser, and only while the Parser is alive. (For a self-contained, owning Document — e.g. for the cache — use the free parse() above instead.) No runtime polymorphism.

VALIDATION: every parse method takes a compile-time bool Validate template parameter, defaulted to true. With Validate=true the grammar checks bounds/structure and rejects malformed input (result JSON null, *ok=false). With Validate=false those checks are guarded by if constexpr and therefore removed from the binary ENTIRELY — there is no runtime flag and no branch, and *ok is not written at all (an unchecked parse has no validity to report). The unchecked form is for trusted, known-well-formed input (e.g. our own cache); feeding it malformed input is undefined behavior. Call it as p.parse<false>(text) / p.parse_owning<false>(text).

Complexity

O(n) in the input length

Allocation

the pools, reused across parses (amortized ~0 after warm-up); owned only for escaped strings

Functions

fn Document parse(std::string_view text, bool *ok=nullptr) source#

Parse text into a Document whose arrays/objects are VIEWS (ArrayView/ObjectView) into this Parser's reused pools — zero per-container allocation, amortized to ~0 across parses.

The result is valid only until the next parse or dump() on this Parser, and while the Parser lives.

Template parameters
Validate

when true (default) reject malformed input; when false all bounds/structure checks are compiled out (trusted, known-well-formed input only — see the class doc).

Parameters
text

the JSON source to parse.

ok

if non-null, set to true on success and false on a parse error (only written when Validate is true).

Returns

the parsed Document (JSON null on error when validating).

Complexity

O(|text|)

Allocation

none after warm-up (reused pools); owned only for escaped strings

fn Document parse_owning(std::string_view text, bool *ok=nullptr) source#

Parse text into a self-contained OWNING Document (OwnedArray/OwnedObject AND owned String<std::string> — strings are copied, not views), fully independent of this Parser and of text once returned.

This is what the free parse() and the cache use.

Template parameters
Validate

as for parse().

Parameters
text

the JSON source to parse.

ok

if non-null, set to true on success and false on a parse error (Validate=true only).

Returns

a self-contained parsed Document (JSON null on error when validating).

Complexity

O(|text|)

Allocation

allocates the owned document tree (arrays, objects, and copied strings)

fn std::string_view dump(const Document &value) source#

Serialize value into the Parser's own REUSED buffer and return a view of it — no per-call allocation after warm-up.

The view is valid until the next dump() on this Parser.

Parameters
value

the document to serialize.

Returns

a std::string_view of the serialized JSON (valid until the next dump()).

Complexity

O(output size)

Allocation

none after warm-up (the buffer is reused)

fn bool parse_value(Cursor &c, Node &out, Builder &b) source#

Constants & variables

var PoolBuilder pool_ source#
var std::vector< Frame > frame_stack_ source#
var std::string dump_buf_ source#