@@ -27,13 +27,13 @@ struct structural_parser : structural_iterator {
27
27
current_string_buf_loc{parser.doc ->string_buf .get ()} {
28
28
}
29
29
30
- WARN_UNUSED really_inline error_code start_scope (bool parent_is_array) {
30
+ WARN_UNUSED really_inline error_code start_scope (bool is_array) {
31
+ depth++;
32
+ if (depth >= parser.max_depth ()) { log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
31
33
parser.containing_scope [depth].tape_index = next_tape_index ();
32
34
parser.containing_scope [depth].count = 0 ;
33
35
tape.skip (); // We don't actually *write* the start element until the end.
34
- parser.is_array [depth] = parent_is_array;
35
- depth++;
36
- if (depth >= parser.max_depth ()) { log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
36
+ parser.is_array [depth] = is_array;
37
37
return SUCCESS;
38
38
}
39
39
@@ -43,24 +43,23 @@ struct structural_parser : structural_iterator {
43
43
parser.containing_scope [depth].count = 0 ;
44
44
tape.skip (); // We don't actually *write* the start element until the end.
45
45
parser.is_array [depth] = false ;
46
- depth++;
47
46
if (depth >= parser.max_depth ()) { log_error (" Exceeded max depth!" ); return DEPTH_ERROR; }
48
47
return SUCCESS;
49
48
}
50
49
51
- WARN_UNUSED really_inline error_code start_object (bool parent_is_array ) {
50
+ WARN_UNUSED really_inline error_code start_object () {
52
51
log_start_value (" object" );
53
- return start_scope (parent_is_array );
52
+ return start_scope (false );
54
53
}
55
54
56
- WARN_UNUSED really_inline error_code start_array (bool parent_is_array ) {
55
+ WARN_UNUSED really_inline error_code start_array () {
57
56
log_start_value (" array" );
58
- return start_scope (parent_is_array );
57
+ return start_scope (true );
59
58
}
60
59
61
60
// this function is responsible for annotating the start of the scope
62
61
really_inline void end_scope (internal::tape_type start, internal::tape_type end) noexcept {
63
- depth-- ;
62
+ // SIMDJSON_ASSUME( depth > 0) ;
64
63
// Write the ending tape element, pointing at the start location
65
64
const uint32_t start_tape_index = parser.containing_scope [depth].tape_index ;
66
65
tape.append (start_tape_index, end);
@@ -70,6 +69,7 @@ struct structural_parser : structural_iterator {
70
69
const uint32_t count = parser.containing_scope [depth].count ;
71
70
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
72
71
tape_writer::write (parser.doc ->tape [start_tape_index], next_tape_index () | (uint64_t (cntsat) << 32 ), start);
72
+ depth--;
73
73
}
74
74
75
75
really_inline uint32_t next_tape_index () {
@@ -86,7 +86,6 @@ struct structural_parser : structural_iterator {
86
86
}
87
87
really_inline void end_document () {
88
88
log_end_value (" document" );
89
- depth--;
90
89
constexpr uint32_t start_tape_index = 0 ;
91
90
tape.append (start_tape_index, internal::tape_type::ROOT);
92
91
tape_writer::write (parser.doc ->tape [start_tape_index], next_tape_index (), internal::tape_type::ROOT);
@@ -117,11 +116,8 @@ struct structural_parser : structural_iterator {
117
116
}
118
117
119
118
// increment_count increments the count of keys in an object or values in an array.
120
- // Note that if you are at the level of the values or elements, the count
121
- // must be increment in the preceding depth (depth-1) where the array or
122
- // the object resides.
123
119
really_inline void increment_count () {
124
- parser.containing_scope [depth - 1 ].count ++; // we have a key value pair in the object at parser.depth - 1
120
+ parser.containing_scope [depth].count ++; // we have a key value pair in the object at parser.depth - 1
125
121
}
126
122
127
123
really_inline uint8_t *on_start_string () noexcept {
@@ -286,12 +282,12 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
286
282
switch (parser.current_char ()) {
287
283
case ' {' : {
288
284
if (parser.empty_object ()) { goto finish; }
289
- SIMDJSON_TRY ( parser.start_object (false ) );
285
+ SIMDJSON_TRY ( parser.start_object () );
290
286
goto object_begin;
291
287
}
292
288
case ' [' : {
293
289
if (parser.empty_array ()) { goto finish; }
294
- SIMDJSON_TRY ( parser.start_array (false ) );
290
+ SIMDJSON_TRY ( parser.start_array () );
295
291
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
296
292
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
297
293
if (!STREAMING) {
@@ -331,12 +327,12 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
331
327
switch (parser.advance_char ()) {
332
328
case ' {' : {
333
329
if (parser.empty_object ()) { break ; };
334
- SIMDJSON_TRY ( parser.start_object (false ) );
330
+ SIMDJSON_TRY ( parser.start_object () );
335
331
goto object_begin;
336
332
}
337
333
case ' [' : {
338
334
if (parser.empty_array ()) { break ; };
339
- SIMDJSON_TRY ( parser.start_array (false ) );
335
+ SIMDJSON_TRY ( parser.start_array () );
340
336
goto array_begin;
341
337
}
342
338
case ' "' : SIMDJSON_TRY ( parser.parse_string () ); break ;
@@ -368,7 +364,7 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
368
364
}
369
365
370
366
scope_end:
371
- if (parser.depth == 1 ) { goto finish; }
367
+ if (parser.depth == 0 ) { goto finish; }
372
368
if (parser.parser .is_array [parser.depth ]) { goto array_continue; }
373
369
goto object_continue;
374
370
@@ -382,12 +378,12 @@ WARN_UNUSED static really_inline error_code parse_structurals(dom_parser_impleme
382
378
switch (parser.advance_char ()) {
383
379
case ' {' : {
384
380
if (parser.empty_object ()) { break ; };
385
- SIMDJSON_TRY ( parser.start_object (true ) );
381
+ SIMDJSON_TRY ( parser.start_object () );
386
382
goto object_begin;
387
383
}
388
384
case ' [' : {
389
385
if (parser.empty_array ()) { break ; };
390
- SIMDJSON_TRY ( parser.start_array (true ) );
386
+ SIMDJSON_TRY ( parser.start_array () );
391
387
goto array_begin;
392
388
}
393
389
case ' "' : SIMDJSON_TRY ( parser.parse_string () ); break ;
0 commit comments