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>
This commit is contained in:
Keith Randall 2024-10-28 14:15:13 -07:00
parent 4dcbb00be2
commit 4b30a40d88
2 changed files with 4 additions and 4 deletions

View file

@ -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.