Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-flatbuffers
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-flatbuffers
Commits
11f25386
Commit
11f25386
authored
10 years ago
by
Wouter van Oortmerssen
Browse files
Options
Downloads
Patches
Plain Diff
Made "field set more than once" check in JSON parser faster.
Change-Id: I3ecc1aa610526c270faa56cc5266f14cd81db247 Tested: on Linux.
parent
ea57dfe8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/flatbuffers/idl.h
+3
-2
3 additions, 2 deletions
include/flatbuffers/idl.h
src/idl_parser.cpp
+10
-4
10 additions, 4 deletions
src/idl_parser.cpp
tests/test.cpp
+1
-1
1 addition, 1 deletion
tests/test.cpp
with
14 additions
and
7 deletions
include/flatbuffers/idl.h
+
3
−
2
View file @
11f25386
...
...
@@ -176,11 +176,12 @@ struct Definition {
};
struct
FieldDef
:
public
Definition
{
FieldDef
()
:
deprecated
(
false
),
padding
(
0
)
{}
FieldDef
()
:
deprecated
(
false
),
padding
(
0
)
,
used
(
false
)
{}
Value
value
;
bool
deprecated
;
size_t
padding
;
// bytes to always pad after this field
size_t
padding
;
// Bytes to always pad after this field.
bool
used
;
// Used during JSON parsing to check for repeated fields.
};
struct
StructDef
:
public
Definition
{
...
...
This diff is collapsed.
Click to expand it.
src/idl_parser.cpp
+
10
−
4
View file @
11f25386
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/test.cpp
+
1
−
1
View file @
11f25386
...
...
@@ -490,7 +490,7 @@ void ErrorTest() {
TestError
(
"union Z { X } struct X { Y:int; }"
,
"only tables"
);
TestError
(
"table X { Y:[int]; YLength:int; }"
,
"clash"
);
TestError
(
"table X { Y:string = 1; }"
,
"scalar"
);
TestError
(
"table X { Y:byte; } root_type X; { Y:1, Y:2 }"
,
"
already set
"
);
TestError
(
"table X { Y:byte; } root_type X; { Y:1, Y:2 }"
,
"
more than once
"
);
}
// Additional parser testing not covered elsewhere.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment