summaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorrw <me@rwinslow.com>2015-05-20 12:00:44 -0700
committerrw <me@rwinslow.com>2015-05-20 12:00:44 -0700
commitc127cf78c207ad85b744b13a3011d86cf86f9c51 (patch)
treec87cf5f7c88f8670fa95741f558e0ccdf763d7cb /go
parent6fffa2a14d1fd35b8c53bc1c8208831420df80a4 (diff)
downloadflatbuffers-c127cf78c207ad85b744b13a3011d86cf86f9c51.tar.gz
flatbuffers-c127cf78c207ad85b744b13a3011d86cf86f9c51.tar.bz2
flatbuffers-c127cf78c207ad85b744b13a3011d86cf86f9c51.zip
Go: CreateString now needs zero allocs.
Big speed boost for the typical use case of building with strings.
Diffstat (limited to 'go')
-rw-r--r--go/builder.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/go/builder.go b/go/builder.go
index 30b09cf9..c7aa264c 100644
--- a/go/builder.go
+++ b/go/builder.go
@@ -281,7 +281,15 @@ func (b *Builder) EndVector(vectorNumElems int) UOffsetT {
// CreateString writes a null-terminated string as a vector.
func (b *Builder) CreateString(s string) UOffsetT {
- return b.CreateByteString([]byte(s))
+ b.Prep(int(SizeUOffsetT), (len(s)+1)*SizeByte)
+ b.PlaceByte(0)
+
+ l := UOffsetT(len(s))
+
+ b.head -= l
+ copy(b.Bytes[b.head:b.head+l], s)
+
+ return b.EndVector(len(s))
}
// CreateByteString writes a byte slice as a string (null-terminated).