Skip to content

Commit

Permalink
Don't send or receive commas
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed Aug 29, 2023
1 parent 3f033d3 commit ab8a27e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
4 changes: 0 additions & 4 deletions include/simdjson/generic/ondemand/json_iterator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ simdjson_warn_unused simdjson_inline error_code json_iterator::skip_child(depth_
case '[': case '{': case ':':
logger::log_start_value(*this, "skip");
break;
// If there is a comma, we have just finished a value in an array/object, and need to get back in
case ',':
logger::log_value(*this, "skip");
break;
// ] or } means we just finished a value and need to jump out of the array/object
case ']': case '}':
logger::log_end_value(*this, "skip");
Expand Down
25 changes: 9 additions & 16 deletions include/simdjson/generic/ondemand/value_iterator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,12 @@ simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::has_n

// It's illegal to call this unless there are more tokens: anything that ends in } or ] is
// obligated to verify there are more tokens if they are not the top level.
switch (*_json_iter->return_current_and_advance()) {
case '}':
logger::log_end_value(*_json_iter, "object");
SIMDJSON_TRY( end_container() );
return false;
case ',':
return true;
default:
return report_error(TAPE_ERROR, "Missing comma between object fields");
if (_json_iter->consume_character('}')) {
logger::log_end_value(*_json_iter, "object");
SIMDJSON_TRY( end_container() );
return false;
}
return true;
}

simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::find_field_raw(const std::string_view key) noexcept {
Expand Down Expand Up @@ -483,16 +479,13 @@ simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::has_n
assert_at_next();

logger::log_event(*this, "has_next_element");
switch (*_json_iter->return_current_and_advance()) {
case ']':
if (_json_iter->consume_character(']')) {
logger::log_end_value(*_json_iter, "array");
SIMDJSON_TRY( end_container() );
return false;
case ',':
_json_iter->descend_to(depth()+1);
return true;
default:
return report_error(TAPE_ERROR, "Missing comma between array elements");
} else {
_json_iter->descend_to(depth()+1);
return true;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/generic/stage1/find_next_document_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ simdjson_inline uint32_t find_next_document_index(dom_parser_implementation &par
auto idxb = parser.structural_indexes[i];
switch (parser.buf[idxb]) {
case ':':
case ',':
continue;
case '}':
obj_cnt--;
Expand All @@ -65,7 +64,6 @@ simdjson_inline uint32_t find_next_document_index(dom_parser_implementation &par
case '{':
case '[':
case ':':
case ',':
continue;
}
// Last document is complete, so the next document will appear after!
Expand Down
8 changes: 4 additions & 4 deletions src/generic/stage1/json_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ simdjson_inline uint64_t json_scanner::next(
//printf("%30.30s: %s\n", "separated_values", format_input_text(in, separated_values));

uint64_t lead_value = scalar_close & separated_values; // 8+LN (+1)
// uint64_t op_without_comma = colon | open | close; // 8+LN (+1) (ternary)
// uint64_t all_structurals = op_without_comma | lead_value; // 20+LN ... 20+LN (+1)
uint64_t op = sep | open | close; // 8+LN (+1) (ternary)
uint64_t all_structurals = op | lead_value; // 12+LN ... 20+LN (+1)
uint64_t op_without_comma = colon | open | close; // 8+LN (+1) (ternary)
uint64_t all_structurals = op_without_comma | lead_value; // 20+LN ... 20+LN (+1)
// uint64_t op = sep | open | close; // 8+LN (+1) (ternary)
// uint64_t all_structurals = op | lead_value; // 12+LN ... 20+LN (+1)
//printf("%30.30s: %s\n", "all_structurals", format_input_text(in, all_structurals));
uint64_t structurals = all_structurals & ~in_string; // (ternary)
//printf("%30.30s: %s\n", "structurals", format_input_text(in, structurals));
Expand Down
31 changes: 17 additions & 14 deletions src/generic/stage2/json_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,18 @@ simdjson_warn_unused simdjson_inline error_code json_iterator::walk_document(V &
}
}

object_continue:
switch (*advance()) {
case ',':
object_continue: {
auto key = advance();
switch (*key) {
case '}': log_end_value("object"); SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
case '"':
SIMDJSON_TRY( visitor.increment_count(*this) );
{
auto key = advance();
if (simdjson_unlikely( *key != '"' )) { log_error("Key string missing at beginning of field in object"); return TAPE_ERROR; }
SIMDJSON_TRY( visitor.visit_key(*this, key) );
}
SIMDJSON_TRY( visitor.visit_key(*this, key) );
goto object_field;
case '}': log_end_value("object"); SIMDJSON_TRY( visitor.visit_object_end(*this) ); goto scope_end;
default: log_error("No comma between object fields"); return TAPE_ERROR;
default:
log_error("Key string missing at beginning of field in object"); return TAPE_ERROR;
}
}

scope_end:
depth--;
Expand Down Expand Up @@ -219,12 +218,16 @@ simdjson_warn_unused simdjson_inline error_code json_iterator::walk_document(V &
}

array_continue:
switch (*advance()) {
case ',': SIMDJSON_TRY( visitor.increment_count(*this) ); goto array_value;
case ']': log_end_value("array"); SIMDJSON_TRY( visitor.visit_array_end(*this) ); goto scope_end;
default: log_error("Missing comma between array values"); return TAPE_ERROR;
if (*peek() == ']') {
advance();
log_end_value("array");
SIMDJSON_TRY( visitor.visit_array_end(*this) );
goto scope_end;
}

SIMDJSON_TRY( visitor.increment_count(*this) );
goto array_value;

document_end:
log_end_value("document");
SIMDJSON_TRY( visitor.visit_document_end(*this) );
Expand Down

0 comments on commit ab8a27e

Please sign in to comment.