mirror of
https://github.com/golang/go
synced 2024-11-21 12:24:39 -07:00
Use the copy function rather than a loop.
R=r CC=golang-dev https://golang.org/cl/882047
This commit is contained in:
parent
d80c78b62f
commit
cd242fb480
@ -1070,10 +1070,8 @@ func Append(slice, data[]byte) []byte {
|
||||
if l + len(data) > cap(slice) { // reallocate
|
||||
// Allocate double what's needed, for future growth.
|
||||
newSlice := make([]byte, (l+len(data))*2)
|
||||
// Copy data (could use bytes.Copy()).
|
||||
for i, c := range slice {
|
||||
newSlice[i] = c
|
||||
}
|
||||
// The copy function is predeclared and works for any slice type.
|
||||
copy(newSlice, slice)
|
||||
slice = newSlice
|
||||
}
|
||||
slice = slice[0:l+len(data)]
|
||||
|
Loading…
Reference in New Issue
Block a user