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).
O(n) in the input length
the pools, reused across parses (amortized ~0 after warm-up); owned only for escaped strings
Functions
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.
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). |
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). |
the parsed Document (JSON null on error when validating).
O(|text|)
none after warm-up (reused pools); owned only for escaped strings
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.
Validate | as for parse(). |
text | the JSON source to parse. |
ok | if non-null, set to true on success and false on a parse error (Validate=true only). |
a self-contained parsed Document (JSON null on error when validating).
O(|text|)
allocates the owned document tree (arrays, objects, and copied strings)
ParsersCompileRun.JsonDomParseSerialize value into the Parser's own REUSED buffer and return a view of it — no per-call allocation after warm-up.
