Skip to content

Commit 9dd6972

Browse files
committed
Remove impossible checks, add EMPTY check to normal parser
1 parent d731a7d commit 9dd6972

1 file changed

Lines changed: 9 additions & 29 deletions

File tree

src/generic/stage2/structural_parser.h

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -271,34 +271,22 @@ struct structural_parser {
271271

272272
template<bool STREAMING>
273273
WARN_UNUSED really_inline error_code finish() {
274-
// Check if we're at (or past) the end
274+
end_document();
275+
275276
if (STREAMING) {
276-
if ( structurals.past_end(parser.n_structural_indexes) ) {
277-
log_error("IMPOSSIBLE: past the end of the JSON!");
278-
return parser.error = TAPE_ERROR;
279-
}
277+
parser.next_structural_index = uint32_t(structurals.next_structural_index());
280278
} else {
281-
// the string might not be NULL terminated.
279+
// Check if we're at the end or if there is stuff left still
282280
if ( !structurals.at_end(parser.n_structural_indexes) ) {
283281
log_error("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
284282
return parser.error = TAPE_ERROR;
285283
}
286284
}
287285

288-
end_document();
289-
290-
if (STREAMING) {
291-
parser.next_structural_index = uint32_t(structurals.next_structural_index());
292-
}
293-
294286
if (depth != 0) {
295287
log_error("Unclosed objects or arrays!");
296288
return parser.error = TAPE_ERROR;
297289
}
298-
if (parser.containing_scope[depth].tape_index != 0) {
299-
log_error("IMPOSSIBLE: root scope tape index did not start at 0!");
300-
return parser.error = TAPE_ERROR;
301-
}
302290

303291
return SUCCESS;
304292
}
@@ -349,22 +337,14 @@ struct structural_parser {
349337
parser.error = UNINITIALIZED;
350338
}
351339

352-
template<bool STREAMING>
353-
WARN_UNUSED really_inline error_code start(size_t len, ret_address_t finish_state) {
354-
if (STREAMING) {
355-
// If there are no structurals left, return EMPTY
356-
if (structurals.at_end(parser.n_structural_indexes)) {
357-
return parser.error = EMPTY;
358-
}
340+
WARN_UNUSED really_inline error_code start(ret_address_t finish_state) {
341+
// If there are no structurals left, return EMPTY
342+
if (structurals.at_end(parser.n_structural_indexes)) {
343+
return parser.error = EMPTY;
359344
}
360345

361346
log_start();
362347
init();
363-
if (!STREAMING) {
364-
if (len > parser.capacity()) {
365-
return parser.error = CAPACITY;
366-
}
367-
}
368348
// Advance to the first character as soon as possible
369349
structurals.advance_char();
370350
// Push the root scope (there is always at least one scope)
@@ -410,7 +390,7 @@ WARN_UNUSED static error_code parse_structurals(dom_parser_implementation &dom_p
410390
dom_parser.doc = &doc;
411391
static constexpr stage2::unified_machine_addresses addresses = INIT_ADDRESSES();
412392
stage2::structural_parser parser(dom_parser, STREAMING ? dom_parser.next_structural_index : 0);
413-
error_code result = parser.start<STREAMING>(dom_parser.len, addresses.finish);
393+
error_code result = parser.start(addresses.finish);
414394
if (result) { return result; }
415395

416396
//

0 commit comments

Comments
 (0)