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
3dd54424
Commit
3dd54424
authored
May 09, 2015
by
rw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove remaining allocs during build
parent
5d68493d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
builder.go
go/builder.go
+22
-4
go_test.go
tests/go_test.go
+2
-1
No files found.
go/builder.go
View file @
3dd54424
...
...
@@ -34,17 +34,35 @@ func NewBuilder(initialSize int) *Builder {
// Reset truncates the underlying Builder buffer, facilitating alloc-free
// reuse of a Builder.
func
(
b
*
Builder
)
Reset
()
{
b
.
Bytes
=
b
.
Bytes
[
:
0
]
b
.
head
=
UOffsetT
(
0
)
b
.
minalign
=
1
if
b
.
Bytes
!=
nil
{
b
.
Bytes
=
b
.
Bytes
[
:
0
]
}
if
b
.
vtables
!=
nil
{
b
.
vtables
=
b
.
vtables
[
:
0
]
}
if
b
.
vtable
!=
nil
{
b
.
vtable
=
b
.
vtable
[
:
0
]
}
}
// StartObject initializes bookkeeping for writing a new object.
func
(
b
*
Builder
)
StartObject
(
numfields
int
)
{
b
.
notNested
()
// use 32-bit offsets so that arithmetic doesn't overflow.
if
cap
(
b
.
vtable
)
<
numfields
||
b
.
vtable
==
nil
{
b
.
vtable
=
make
([]
UOffsetT
,
numfields
)
}
else
{
b
.
vtable
=
b
.
vtable
[
:
numfields
]
for
i
:=
0
;
i
<
len
(
b
.
vtable
)
;
i
++
{
b
.
vtable
[
i
]
=
0
}
}
b
.
objectEnd
=
b
.
Offset
()
b
.
minalign
=
1
}
...
...
@@ -146,7 +164,7 @@ func (b *Builder) WriteVtable() (n UOffsetT) {
SOffsetT
(
existingVtable
)
-
SOffsetT
(
objectOffset
))
}
b
.
vtable
=
nil
b
.
vtable
=
b
.
vtable
[
:
0
]
return
objectOffset
}
...
...
@@ -269,7 +287,7 @@ func (b *Builder) CreateString(s string) UOffsetT {
return
b
.
CreateByteString
([]
byte
(
s
))
}
// CreateByteString writes a
null-terminated byteslice as a vector
.
// CreateByteString writes a
byte slice as a string (null-terminated)
.
func
(
b
*
Builder
)
CreateByteString
(
s
[]
byte
)
UOffsetT
{
b
.
Prep
(
int
(
SizeUOffsetT
),
(
len
(
s
)
+
1
)
*
SizeByte
)
b
.
PlaceByte
(
0
)
...
...
@@ -297,7 +315,7 @@ func (b *Builder) CreateByteVector(v []byte) UOffsetT {
func
(
b
*
Builder
)
notNested
()
{
// Check that no other objects are being built while making this
// object. If not, panic:
if
b
.
vtable
!=
nil
{
if
len
(
b
.
vtable
)
>
0
{
panic
(
"non-inline data write inside of object"
)
}
}
...
...
tests/go_test.go
View file @
3dd54424
...
...
@@ -1254,7 +1254,8 @@ func BenchmarkBuildGold(b *testing.B) {
reuse_fred
:=
[]
byte
(
"Fred"
)
b
.
SetBytes
(
bytes_length
)
bldr
:=
flatbuffers
.
NewBuilder
(
512
)
bldr
:=
flatbuffers
.
NewBuilder
(
0
)
b
.
ResetTimer
()
b
.
ReportAllocs
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
bldr
.
Reset
()
...
...
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