mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
4dcbb00be2
commit
4b30a40d88
2 changed files with 4 additions and 4 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ func concatstrings(buf *tmpBuf, a []string) string {
|
|||
}
|
||||
s, b := rawstringtmp(buf, l)
|
||||
for _, x := range a {
|
||||
copy(b, x)
|
||||
b = b[len(x):]
|
||||
n := copy(b, x)
|
||||
b = b[n:]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue