1
0
mirror of https://github.com/golang/go synced 2024-09-29 20:24:34 -06:00

bytes, strings: use copy in Repeat

R=golang-dev, dave, bradfitz, adg
CC=golang-dev
https://golang.org/cl/13249043
This commit is contained in:
Evan Shaw 2013-08-27 09:21:08 +10:00 committed by Andrew Gerrand
parent b2e937970b
commit f033d988b1
2 changed files with 2 additions and 8 deletions

View 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
}

View 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)
}