1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:54: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:
Ian Lance Taylor 2010-04-13 13:05:29 -07:00
parent d80c78b62f
commit cd242fb480

View File

@ -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)]