diff options
| author | Russ Cox <rsc@golang.org> | 2026-02-11 10:25:42 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2026-02-26 12:08:56 -0800 |
| commit | 753022f82fc54dab5e348fac3706a9df8afc5cb5 (patch) | |
| tree | 5e71a05af331684996e3439b1694b29631e15717 /src/crypto | |
| parent | 89d92fc21166c27db7d4203d93019e33f8cb9695 (diff) | |
| download | go-753022f82fc54dab5e348fac3706a9df8afc5cb5.tar.xz | |
crypto/internal/boring: replace slice growth loop with slices.Grow
If dst is nil and len(plaintext) is 10MB, the slice growth loop
allocates about 70MB. slices.Grow only allocates 10MB.
Noticed on a real profile in a program built with boringcrypto.
Change-Id: Iecc727b961273d4f2d553669d43014c507e25df8
Reviewed-on: https://go-review.googlesource.com/c/go/+/744400
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'src/crypto')
| -rw-r--r-- | src/crypto/internal/boring/aes.go | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/crypto/internal/boring/aes.go b/src/crypto/internal/boring/aes.go index d18ed5cdc5..a2aa7eb2df 100644 --- a/src/crypto/internal/boring/aes.go +++ b/src/crypto/internal/boring/aes.go @@ -48,6 +48,7 @@ import ( "crypto/cipher" "errors" "runtime" + "slices" "strconv" "unsafe" ) @@ -323,9 +324,7 @@ func (g *aesGCM) Seal(dst, nonce, plaintext, additionalData []byte) []byte { // Make room in dst to append plaintext+overhead. n := len(dst) - for cap(dst) < n+len(plaintext)+gcmTagSize { - dst = append(dst[:cap(dst)], 0) - } + dst = slices.Grow(dst, len(plaintext)+gcmTagSize) dst = dst[:n+len(plaintext)+gcmTagSize] // Check delayed until now to make sure len(dst) is accurate. |
