@@ -31,31 +31,25 @@ struct number_writer {
31
31
struct structural_parser {
32
32
structural_iterator structurals;
33
33
parser &doc_parser;
34
- /* * Next write location in the string buf for stage 2 parsing */
35
- uint8_t *¤t_string_buf_loc;
36
34
uint32_t depth;
37
35
38
36
really_inline structural_parser (
39
37
const uint8_t *buf,
40
38
size_t len,
41
39
parser &_doc_parser,
42
- size_t &next_structural,
43
- uint8_t *&_current_string_buf_loc
40
+ size_t &next_structural
44
41
) : structurals(buf, len, _doc_parser.structural_indexes.get(), next_structural),
45
42
doc_parser{_doc_parser},
46
- current_string_buf_loc{_current_string_buf_loc},
47
43
depth{0 } {
48
44
}
49
45
50
46
really_inline structural_parser (
51
47
const uint8_t *buf,
52
48
parser &_doc_parser,
53
49
size_t &next_structural,
54
- uint8_t *&_current_string_buf_loc,
55
50
uint32_t _depth
56
51
) : structurals(buf, 0 , _doc_parser.structural_indexes.get(), next_structural),
57
52
doc_parser{_doc_parser},
58
- current_string_buf_loc{_current_string_buf_loc},
59
53
depth{_depth} {
60
54
}
61
55
@@ -112,20 +106,20 @@ struct structural_parser {
112
106
113
107
really_inline uint8_t *on_start_string () noexcept {
114
108
// we advance the point, accounting for the fact that we have a NULL termination
115
- write_tape (current_string_buf_loc - doc_parser.doc .string_buf .get (), internal::tape_type::STRING);
116
- return current_string_buf_loc + sizeof (uint32_t );
109
+ write_tape (doc_parser. current_string_buf_loc - doc_parser.doc .string_buf .get (), internal::tape_type::STRING);
110
+ return doc_parser. current_string_buf_loc + sizeof (uint32_t );
117
111
}
118
112
119
113
really_inline void on_end_string (uint8_t *dst) noexcept {
120
- uint32_t str_length = uint32_t (dst - (current_string_buf_loc + sizeof (uint32_t )));
114
+ uint32_t str_length = uint32_t (dst - (doc_parser. current_string_buf_loc + sizeof (uint32_t )));
121
115
// TODO check for overflow in case someone has a crazy string (>=4GB?)
122
116
// But only add the overflow check when the document itself exceeds 4GB
123
117
// Currently unneeded because we refuse to parse docs larger or equal to 4GB.
124
- memcpy (current_string_buf_loc, &str_length, sizeof (uint32_t ));
118
+ memcpy (doc_parser. current_string_buf_loc , &str_length, sizeof (uint32_t ));
125
119
// NULL termination is still handy if you expect all your strings to
126
120
// be NULL terminated? It comes at a small cost
127
121
*dst = 0 ;
128
- current_string_buf_loc = dst + 1 ;
122
+ doc_parser. current_string_buf_loc = dst + 1 ;
129
123
}
130
124
131
125
WARN_UNUSED really_inline bool parse_string (bool key = false ) {
@@ -250,19 +244,17 @@ struct structural_parser {
250
244
}
251
245
252
246
WARN_UNUSED really_inline bool parse_object () {
253
- return parse_object (structurals.buf , doc_parser, structurals.next_structural , current_string_buf_loc, depth+1 );
247
+ return parse_object (structurals.buf , doc_parser, structurals.next_structural , depth+1 );
254
248
}
255
249
256
250
WARN_UNUSED static bool parse_object (
257
251
const uint8_t *buf,
258
252
parser &doc_parser,
259
253
size_t &next_structural,
260
- uint8_t *¤t_string_buf_loc,
261
254
uint32_t depth) {
262
- structural_parser parser (buf, doc_parser, next_structural, current_string_buf_loc, depth);
255
+ structural_parser parser (buf, doc_parser, next_structural, depth);
263
256
bool result = parser.parse_object_inline ();
264
257
next_structural = parser.structurals .next_structural ;
265
- current_string_buf_loc = parser.current_string_buf_loc ;
266
258
return result;
267
259
}
268
260
@@ -310,19 +302,17 @@ struct structural_parser {
310
302
}
311
303
312
304
WARN_UNUSED really_inline bool parse_array () {
313
- return parse_array (structurals.buf , doc_parser, structurals.next_structural , current_string_buf_loc, depth+1 );
305
+ return parse_array (structurals.buf , doc_parser, structurals.next_structural , depth+1 );
314
306
}
315
307
316
308
WARN_UNUSED static bool parse_array (
317
309
const uint8_t *buf,
318
310
parser &doc_parser,
319
311
size_t &next_structural,
320
- uint8_t *¤t_string_buf_loc,
321
312
uint32_t depth) {
322
- structural_parser parser (buf, doc_parser, next_structural, current_string_buf_loc, depth);
313
+ structural_parser parser (buf, doc_parser, next_structural, depth);
323
314
bool result = parser.parse_array_inline ();
324
315
next_structural = parser.structurals .next_structural ;
325
- current_string_buf_loc = parser.current_string_buf_loc ;
326
316
return result;
327
317
}
328
318
@@ -361,10 +351,6 @@ struct structural_parser {
361
351
return on_error (TAPE_ERROR);
362
352
}
363
353
end_document (0 , 1 );
364
- if (depth != 0 ) {
365
- log_error (" Unclosed objects or arrays!" );
366
- return on_error (TAPE_ERROR);
367
- }
368
354
369
355
return on_success (SUCCESS);
370
356
}
@@ -420,7 +406,7 @@ struct structural_parser {
420
406
}
421
407
422
408
really_inline void init () {
423
- current_string_buf_loc = doc_parser.doc .string_buf .get ();
409
+ doc_parser. current_string_buf_loc = doc_parser.doc .string_buf .get ();
424
410
doc_parser.current_loc = 0 ;
425
411
doc_parser.valid = false ;
426
412
doc_parser.error = UNINITIALIZED;
@@ -476,8 +462,7 @@ struct structural_parser {
476
462
***********/
477
463
WARN_UNUSED error_code implementation::stage2 (const uint8_t *buf, size_t len, parser &doc_parser) const noexcept {
478
464
size_t next_structural = 0 ;
479
- uint8_t *current_string_buf_loc = doc_parser.doc .string_buf .get ();
480
- stage2::structural_parser parser (buf, len, doc_parser, next_structural, current_string_buf_loc);
465
+ stage2::structural_parser parser (buf, len, doc_parser, next_structural);
481
466
error_code result = parser.start (len);
482
467
if (result) { return result; }
483
468
0 commit comments