mirror of
https://github.com/golang/go
synced 2024-11-24 23:17:57 -07: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:
parent
b2e937970b
commit
f033d988b1
@ -375,10 +375,7 @@ func Repeat(b []byte, count int) []byte {
|
|||||||
nb := make([]byte, len(b)*count)
|
nb := make([]byte, len(b)*count)
|
||||||
bp := 0
|
bp := 0
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
for j := 0; j < len(b); j++ {
|
bp += copy(nb[bp:], b)
|
||||||
nb[bp] = b[j]
|
|
||||||
bp++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nb
|
return nb
|
||||||
}
|
}
|
||||||
|
@ -425,10 +425,7 @@ func Repeat(s string, count int) string {
|
|||||||
b := make([]byte, len(s)*count)
|
b := make([]byte, len(s)*count)
|
||||||
bp := 0
|
bp := 0
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
for j := 0; j < len(s); j++ {
|
bp += copy(b[bp:], s)
|
||||||
b[bp] = s[j]
|
|
||||||
bp++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user