From: Ian Lance Taylor Date: Tue, 13 Apr 2010 20:05:29 +0000 (-0700) Subject: Use the copy function rather than a loop. X-Git-Tag: weekly.2010-04-13~6 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cd242fb48063685ab3f48661c265bfb661bdc3d9;p=gostls13.git Use the copy function rather than a loop. R=r CC=golang-dev https://golang.org/cl/882047 --- diff --git a/doc/effective_go.html b/doc/effective_go.html index ce5fcb99d5..415ae09626 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -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)]