Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
8bb45dc0
Commit
8bb45dc0
authored
Dec 07, 2015
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1029 from belldon/vtable_reuse
Update C# FlatBufferBuilder to reuse vtable array
parents
8e6758d2
d5a113e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
FlatBufferBuilder.cs
net/FlatBuffers/FlatBufferBuilder.cs
+27
-12
No files found.
net/FlatBuffers/FlatBufferBuilder.cs
View file @
8bb45dc0
...
...
@@ -14,9 +14,11 @@
* limitations under the License.
*/
using
System
;
using
System.Text
;
namespace
FlatBuffers
{
/// <summary>
...
...
@@ -29,8 +31,10 @@ namespace FlatBuffers
private
ByteBuffer
_bb
;
private
int
_minAlign
=
1
;
// The vtable for the current table, null otherwise.
private
int
[]
_vtable
;
// The vtable for the current table (if _vtableSize >= 0)
private
int
[]
_vtable
=
new
int
[
16
];
// The size of the vtable. -1 indicates no vtable
private
int
_vtableSize
=
-
1
;
// Starting offset of the current struct/table.
private
int
_objectStart
;
// List of offsets of all vtables.
...
...
@@ -54,9 +58,9 @@ namespace FlatBuffers
_space
=
_bb
.
Length
;
_bb
.
Reset
();
_minAlign
=
1
;
_vtable
=
null
;
while
(
_vtableSize
>
0
)
_vtable
[--
_vtableSize
]
=
0
;
_vtableSize
=
-
1
;
_objectStart
=
0
;
_vtables
=
new
int
[
16
];
_numVtables
=
0
;
_vectorNumElems
=
0
;
}
...
...
@@ -226,15 +230,22 @@ namespace FlatBuffers
{
// You should not be creating any other objects or strings/vectors
// while an object is being constructed
if
(
_vtable
!=
null
)
if
(
_vtable
Size
>=
0
)
throw
new
Exception
(
"FlatBuffers: object serialization must not be nested."
);
}
public
void
StartObject
(
int
numfields
)
{
if
(
numfields
<
0
)
throw
new
ArgumentOutOfRangeException
(
"Flatbuffers: invalid numfields"
);
NotNested
();
_vtable
=
new
int
[
numfields
];
if
(
_vtable
.
Length
<
numfields
)
_vtable
=
new
int
[
numfields
];
_vtableSize
=
numfields
;
_objectStart
=
Offset
;
}
...
...
@@ -243,6 +254,9 @@ namespace FlatBuffers
// buffer.
public
void
Slot
(
int
voffset
)
{
if
(
voffset
>=
_vtableSize
)
throw
new
IndexOutOfRangeException
(
"Flatbuffers: invalid voffset"
);
_vtable
[
voffset
]
=
Offset
;
}
...
...
@@ -284,30 +298,31 @@ namespace FlatBuffers
public
int
EndObject
()
{
if
(
_vtable
==
null
)
if
(
_vtableSize
<
0
)
throw
new
InvalidOperationException
(
"Flatbuffers: calling endObject without a startObject"
);
AddInt
((
int
)
0
);
var
vtableloc
=
Offset
;
// Write out the current vtable.
for
(
int
i
=
_vtable
.
Length
-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
_vtable
Size
-
1
;
i
>=
0
;
i
--)
{
// Offset relative to the start of the table.
short
off
=
(
short
)(
_vtable
[
i
]
!=
0
?
vtableloc
-
_vtable
[
i
]
:
0
);
AddShort
(
off
);
// clear out written entry
_vtable
[
i
]
=
0
;
}
const
int
standardFields
=
2
;
// The fields below:
AddShort
((
short
)(
vtableloc
-
_objectStart
));
AddShort
((
short
)((
_vtable
.
Length
+
standardFields
)
*
AddShort
((
short
)((
_vtable
Size
+
standardFields
)
*
sizeof
(
short
)));
// Search for an existing vtable that matches the current one.
int
existingVtable
=
0
;
for
(
int
i
=
0
;
i
<
_numVtables
;
i
++)
{
int
vt1
=
_bb
.
Length
-
_vtables
[
i
];
int
vt2
=
_space
;
...
...
@@ -348,7 +363,7 @@ namespace FlatBuffers
_bb
.
PutInt
(
_bb
.
Length
-
vtableloc
,
Offset
-
vtableloc
);
}
_vtable
=
null
;
_vtable
Size
=
-
1
;
return
vtableloc
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment