]> Cypherpunks repositories - gostls13.git/commit
encoding/binary: add AppendByteOrder
authorJoe Tsai <joetsai@digital-static.net>
Wed, 16 Feb 2022 00:59:59 +0000 (16:59 -0800)
committerJoseph Tsai <joetsai@digital-static.net>
Wed, 2 Mar 2022 18:21:38 +0000 (18:21 +0000)
commit986b04c0f12efa1c57293f147a9e734ec71f0363
tree8bb2e6116686ba5445aa4b813f002340e73a992b
parenta5b8b56d1d05d186999e4abf1e2147b6aa203ec9
encoding/binary: add AppendByteOrder

AppendByteOrder specifies new methods for LittleEndian and BigEndian
for appending an unsigned integer to a byte slice.

The performance of AppendXXX methods are slower than PutXXX methods
since the former needs to do a few slice operations,
while the latter is essentially a single integer store.
In practice, existing usages of PutXXX performed slicing operations
around the call such that this cost was present, regardless.

name                           time/op
PutUint16-24                   0.48ns ± 2%
AppendUint16-24                1.54ns ± 1%
PutUint32-24                   0.46ns ± 2%
AppendUint32-24                0.89ns ± 1%
PutUint64-24                   0.46ns ± 2%
AppendUint64-24                0.89ns ± 1%
LittleEndianPutUint16-24       0.47ns ± 2%
LittleEndianAppendUint16-24    1.54ns ± 1%
LittleEndianPutUint32-24       0.45ns ± 3%
LittleEndianAppendUint32-24    0.92ns ± 2%
LittleEndianPutUint64-24       0.46ns ± 3%
LittleEndianAppendUint64-24    0.95ns ± 4%

Fixes #50601

Change-Id: I33d2bbc93a3ce01a9269feac33a2432bc1166ead
Reviewed-on: https://go-review.googlesource.com/c/go/+/386017
Trust: Joseph Tsai <joetsai@digital-static.net>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/encoding/binary/binary.go
src/encoding/binary/binary_test.go