aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2010-04-13 13:05:29 -0700
committerIan Lance Taylor <iant@golang.org>2010-04-13 13:05:29 -0700
commitcd242fb48063685ab3f48661c265bfb661bdc3d9 (patch)
tree09cbe1c6054e2456c226ef96cb5a1315caf56042
parentd80c78b62f8ca71355f4b57c87791e8005033ff2 (diff)
downloadgo-cd242fb48063685ab3f48661c265bfb661bdc3d9.tar.gz
go-cd242fb48063685ab3f48661c265bfb661bdc3d9.zip
Use the copy function rather than a loop.
R=r CC=golang-dev https://golang.org/cl/882047
-rw-r--r--doc/effective_go.html6
1 files changed, 2 insertions, 4 deletions
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) &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)]