]> Cypherpunks repositories - gostls13.git/commitdiff
bytes, strings: use copy in Repeat
authorEvan Shaw <chickencha@gmail.com>
Mon, 26 Aug 2013 23:21:08 +0000 (09:21 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 26 Aug 2013 23:21:08 +0000 (09:21 +1000)
R=golang-dev, dave, bradfitz, adg
CC=golang-dev
https://golang.org/cl/13249043

src/pkg/bytes/bytes.go
src/pkg/strings/strings.go

index 405b10a1dbf00083ace24115697986774395ce04..01a5d9ae4ecaa7d5622efd2c4c8ff36beaf8807b 100644 (file)
@@ -375,10 +375,7 @@ func Repeat(b []byte, count int) []byte {
        nb := make([]byte, len(b)*count)
        bp := 0
        for i := 0; i < count; i++ {
-               for j := 0; j < len(b); j++ {
-                       nb[bp] = b[j]
-                       bp++
-               }
+               bp += copy(nb[bp:], b)
        }
        return nb
 }
index 4d33f1ecd7c79acddd06fca133a1a1b6bbf9a69b..5d46211d84e5e395ae0c7a0479c68f8ffcbda6db 100644 (file)
@@ -425,10 +425,7 @@ func Repeat(s string, count int) string {
        b := make([]byte, len(s)*count)
        bp := 0
        for i := 0; i < count; i++ {
-               for j := 0; j < len(s); j++ {
-                       b[bp] = s[j]
-                       bp++
-               }
+               bp += copy(b[bp:], s)
        }
        return string(b)
 }