Consolidate start_object calls

This commit is contained in:
John Keiser 2020-08-03 18:45:37 -07:00
parent 03aaf189c1
commit 5b05d126b4
1 changed files with 2 additions and 6 deletions

View File

@ -125,12 +125,10 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
switch (*value) { switch (*value) {
case '{': { case '{': {
if (empty_object(builder)) { goto document_end; } if (empty_object(builder)) { goto document_end; }
SIMDJSON_TRY( start_object(builder) );
goto object_begin; goto object_begin;
} }
case '[': { case '[': {
if (empty_array(builder)) { goto document_end; } if (empty_array(builder)) { goto document_end; }
SIMDJSON_TRY( start_array(builder) );
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get // Make sure the outer array is closed before continuing; otherwise, there are ways we could get
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906 // into memory corruption. See https://github.com/simdjson/simdjson/issues/906
if (!STREAMING) { if (!STREAMING) {
@ -151,6 +149,7 @@ WARN_UNUSED really_inline error_code structural_parser::parse(T &builder) noexce
// Object parser states // Object parser states
// //
object_begin: { object_begin: {
SIMDJSON_TRY( start_object(builder) );
const uint8_t *key = advance(); const uint8_t *key = advance();
if (*key != '"') { if (*key != '"') {
log_error("Object does not start with a key"); log_error("Object does not start with a key");
@ -167,12 +166,10 @@ object_field: {
switch (*value) { switch (*value) {
case '{': { case '{': {
if (empty_object(builder)) { break; }; if (empty_object(builder)) { break; };
SIMDJSON_TRY( start_object(builder) );
goto object_begin; goto object_begin;
} }
case '[': { case '[': {
if (empty_array(builder)) { break; }; if (empty_array(builder)) { break; };
SIMDJSON_TRY( start_array(builder) );
goto array_begin; goto array_begin;
} }
default: { default: {
@ -210,6 +207,7 @@ scope_end: {
// Array parser states // Array parser states
// //
array_begin: { array_begin: {
SIMDJSON_TRY( start_array(builder) );
builder.increment_count(*this); builder.increment_count(*this);
} // array_begin: } // array_begin:
@ -218,12 +216,10 @@ array_value: {
switch (*value) { switch (*value) {
case '{': { case '{': {
if (empty_object(builder)) { break; }; if (empty_object(builder)) { break; };
SIMDJSON_TRY( start_object(builder) );
goto object_begin; goto object_begin;
} }
case '[': { case '[': {
if (empty_array(builder)) { break; }; if (empty_array(builder)) { break; };
SIMDJSON_TRY( start_array(builder) );
goto array_begin; goto array_begin;
} }
default: { default: {