Commit cd242fb4 authored by Ian Lance Taylor's avatar Ian Lance Taylor

Use the copy function rather than a loop.

R=r
CC=golang-dev
https://golang.org/cl/882047
parent d80c78b6
...@@ -1070,10 +1070,8 @@ func Append(slice, data[]byte) []byte { ...@@ -1070,10 +1070,8 @@ func Append(slice, data[]byte) []byte {
if l + len(data) > cap(slice) { // reallocate if l + len(data) > cap(slice) { // reallocate
// Allocate double what's needed, for future growth. // Allocate double what's needed, for future growth.
newSlice := make([]byte, (l+len(data))*2) newSlice := make([]byte, (l+len(data))*2)
// Copy data (could use bytes.Copy()). // The copy function is predeclared and works for any slice type.
for i, c := range slice { copy(newSlice, slice)
newSlice[i] = c
}
slice = newSlice slice = newSlice
} }
slice = slice[0:l+len(data)] slice = slice[0:l+len(data)]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment