diff options
| author | Keith Randall <khr@golang.org> | 2024-10-28 14:15:13 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2024-10-29 16:47:05 +0000 |
| commit | 4b30a40d8856cc3f6c8f629a9f825feeaf9848af (patch) | |
| tree | 696fe852c91504a49caa1705b7f5db53d751cd9c /src/bytes/buffer.go | |
| parent | 4dcbb00be200bc1f88b534c311ed4289eb2fbdd5 (diff) | |
| download | go-4b30a40d8856cc3f6c8f629a9f825feeaf9848af.tar.xz | |
strings,bytes: use result of copy in subsequent slicing
This can get rid of a bounds check.
Followup to CL 622240.
Change-Id: I9d0a2c0408b8d274c46136d32d7a5fb09b4aad1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/622955
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/bytes/buffer.go')
| -rw-r--r-- | src/bytes/buffer.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go index 4176d670ec..f90d9eca0f 100644 --- a/src/bytes/buffer.go +++ b/src/bytes/buffer.go @@ -247,8 +247,8 @@ func growSlice(b []byte, n int) []byte { c = 2 * cap(b) } b2 := append([]byte(nil), make([]byte, c)...) - copy(b2, b) - return b2[:len(b)] + i := copy(b2, b) + return b2[:i] } // WriteTo writes data to w until the buffer is drained or an error occurs. |
