]> Cypherpunks repositories - gostls13.git/commit
encoding/binary: speed up Size
authorLorenz Bauer <oss@lmb.io>
Thu, 16 May 2024 10:22:36 +0000 (11:22 +0100)
committerGopher Robot <gobot@golang.org>
Mon, 20 May 2024 19:16:18 +0000 (19:16 +0000)
commit447ad32a1db8492ce8549ae27e0b72b611938253
treebb1628bded4f12ec83bf97829e2c1605666145b1
parent04bf36e97305197d09554739391f607afde1fd74
encoding/binary: speed up Size

Size() is currently not called from the fast path, since the package
handles the buffer sizing for Read and Write internally. This will change
when adding Append() because callers can use Size to avoid allocations when
writing into bytes.Buffer via AvailableBuffer for example.

Add a fast path for simple types and extend the existing struct size cache
to arrays of structs.

Change-Id: I3af16a2b6c9e2dbe6166a2f8c96bcd2e936719e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/584358
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Austin Clements <austin@google.com>
src/encoding/binary/binary.go
src/encoding/binary/binary_test.go