Made "field set more than once" check in JSON parser faster.

Change-Id: I3ecc1aa610526c270faa56cc5266f14cd81db247
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2014-09-04 11:57:09 -07:00
parent ea57dfe897
commit 11f2538610
3 changed files with 14 additions and 7 deletions

View File

@@ -457,10 +457,6 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) {
|| struct_def.fields.vec[fieldn] != field)) {
Error("struct field appearing out of order: " + name);
}
for (auto it = field_stack_.rbegin();
it != field_stack_.rbegin() + fieldn; ++it) {
if (it->second == field) Error("field already set: " + name);
}
Expect(':');
Value val = field->value;
ParseAnyValue(val, field);
@@ -469,6 +465,16 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) {
if (IsNext('}')) break;
Expect(',');
}
for (auto it = field_stack_.rbegin();
it != field_stack_.rbegin() + fieldn; ++it) {
if (it->second->used)
Error("field set more than once: " + it->second->name);
it->second->used = true;
}
for (auto it = field_stack_.rbegin();
it != field_stack_.rbegin() + fieldn; ++it) {
it->second->used = false;
}
if (struct_def.fixed && fieldn != struct_def.fields.vec.size())
Error("incomplete struct initialization: " + struct_def.name);
auto start = struct_def.fixed