mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 17:20:00 +00:00
Add CreateByteVector function to Go's builder
This function gets around the inefficiency of populating a [ubyte] vector byte by byte. Since ubyte vectors are probably the most commonly used type of generic byte buffer, this seems like a worthwhile thing to create a fast path for. Benchmarks show a 6x improvement in throughput on x64. There is a new test verifying the functionality of the function. Change-Id: I82e0228ae0f815dd7ea89bf168b8c1925f3ce0d7
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
4464405250
commit
6a0126340a
@@ -259,6 +259,18 @@ func (b *Builder) CreateString(s string) UOffsetT {
|
||||
return b.EndVector(len(x))
|
||||
}
|
||||
|
||||
// CreateByteVector writes a ubyte vector
|
||||
func (b *Builder) CreateByteVector(v []byte) UOffsetT {
|
||||
b.Prep(int(SizeUOffsetT), len(v)*SizeByte)
|
||||
|
||||
l := UOffsetT(len(v))
|
||||
|
||||
b.head -= l
|
||||
copy(b.Bytes[b.head:b.head+l], v)
|
||||
|
||||
return b.EndVector(len(v))
|
||||
}
|
||||
|
||||
func (b *Builder) notNested() {
|
||||
// Check that no other objects are being built while making this
|
||||
// object. If not, panic:
|
||||
|
||||
Reference in New Issue
Block a user