mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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
2 changed files with 2 additions and 8 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue