2
0
mirror of https://github.com/boostorg/json.git synced 2026-01-28 07:12:20 +00:00

Add storage_ptr constructor to parser

close #124
This commit is contained in:
Krystian Stasiowski
2020-06-27 15:46:17 -04:00
committed by Vinnie Falco
parent f330c7a7c1
commit 098be8a6c7
2 changed files with 46 additions and 8 deletions

View File

@@ -154,7 +154,14 @@ parser::
}
parser::
parser()
parser() noexcept
: parser(storage_ptr())
{
}
parser::
parser(storage_ptr sp) noexcept
: rs_(std::move(sp))
{
lev_.st = state::need_start;
}

View File

@@ -56,14 +56,17 @@ namespace json {
to bound the amount of work performed in each
parsing cycle.
<br>
@par Intermediate Storage
The parser may dynamically allocate intermediate
storage as needed to accommodate the nesting level
of the JSON being parsed. This storage is freed
when the parser is destroyed, allowing the parser
to cheaply re-use this memory when parsing
subsequent JSONs, improving performance.
of the JSON being parsed. Intermediate storage is
allocated using the @ref storage_ptr passed to
the constructor; if no such argument is specified,
the default memory resource will be used instead.
This storage is freed when the parser is destroyed,
allowing the parser to cheaply reuse this memory
when parsing subsequent JSONs, improving performance.
*/
class parser : public basic_parser
{
@@ -98,11 +101,39 @@ public:
/** Default constructor.
Constructs an empty parser that uses the
default memory resource to allocate
intermediate storage.
@note
Before any JSON can be parsed, the function
@ref start must be called.
@ref start must be called.
*/
BOOST_JSON_DECL
parser();
parser() noexcept;
/** Constructor.
Constructs a empty parser using the supplied
@ref storage_ptr to allocate
intermediate storage.
@note
Before any JSON can be parsed, the function
@ref start must be called.
<br>
The `sp` parameter is only used to
allocate intermediate storage; will not be used
for the @ref value returned by @ref release.
@param sp The @ref storage_ptr to use for
intermediate storage allocations.
*/
BOOST_JSON_DECL
explicit
parser(storage_ptr sp) noexcept;
/** Reserve internal storage space.