]> Cypherpunks repositories - gostls13.git/commitdiff
Use the copy function rather than a loop.
authorIan Lance Taylor <iant@golang.org>
Tue, 13 Apr 2010 20:05:29 +0000 (13:05 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 13 Apr 2010 20:05:29 +0000 (13:05 -0700)
R=r
CC=golang-dev
https://golang.org/cl/882047

doc/effective_go.html

index ce5fcb99d5b2018da489afd44f1659e17ac12505..415ae09626c8c978600eeedc2ca49befac49c215 100644 (file)
@@ -1070,10 +1070,8 @@ func Append(slice, data[]byte) []byte {
     if l + len(data) &gt; 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)]