summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Atkinson <brian@atkinson.mn>2018-07-15 16:38:55 -0700
committerBrian Atkinson <brian@atkinson.mn>2018-07-15 16:47:17 -0700
commite2eb6af3e3ebecff8647c01f81eac92bf864fc31 (patch)
treeb0132dae8c90091b9557cb9461a997e6a6610a6e
parentb188fde27eeb2093ce8c5198de3eb46ee1eedabb (diff)
downloadflatbuffers-e2eb6af3e3ebecff8647c01f81eac92bf864fc31.tar.gz
flatbuffers-e2eb6af3e3ebecff8647c01f81eac92bf864fc31.tar.bz2
flatbuffers-e2eb6af3e3ebecff8647c01f81eac92bf864fc31.zip
[Go] Unroll WriteUint64 and WriteInt64.
This enables both WriteUint64 and WriteInt64 to both be inlined as well as implemented with a single assembly instruction. The current Go compiler refuses to inline functions with for loops. The compiler is also not smart enough to produce a single assembly instruction for the for-loop.
-rw-r--r--go/encode.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/go/encode.go b/go/encode.go
index 48ff36ef..6e47c056 100644
--- a/go/encode.go
+++ b/go/encode.go
@@ -159,9 +159,14 @@ func WriteUint32(buf []byte, n uint32) {
// WriteUint64 encodes a little-endian uint64 into a byte slice.
func WriteUint64(buf []byte, n uint64) {
- for i := uint(0); i < uint(SizeUint64); i++ {
- buf[i] = byte(n >> (i * 8))
- }
+ buf[0] = byte(n)
+ buf[1] = byte(n >> 8)
+ buf[2] = byte(n >> 16)
+ buf[3] = byte(n >> 24)
+ buf[4] = byte(n >> 32)
+ buf[5] = byte(n >> 40)
+ buf[6] = byte(n >> 48)
+ buf[7] = byte(n >> 56)
}
// WriteInt8 encodes a little-endian int8 into a byte slice.
@@ -185,9 +190,14 @@ func WriteInt32(buf []byte, n int32) {
// WriteInt64 encodes a little-endian int64 into a byte slice.
func WriteInt64(buf []byte, n int64) {
- for i := uint(0); i < uint(SizeInt64); i++ {
- buf[i] = byte(n >> (i * 8))
- }
+ buf[0] = byte(n)
+ buf[1] = byte(n >> 8)
+ buf[2] = byte(n >> 16)
+ buf[3] = byte(n >> 24)
+ buf[4] = byte(n >> 32)
+ buf[5] = byte(n >> 40)
+ buf[6] = byte(n >> 48)
+ buf[7] = byte(n >> 56)
}
// WriteFloat32 encodes a little-endian float32 into a byte slice.