1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:00:13 -07:00

strings: avoid pointless slice growth in makeBenchInputHard

LGTM=ruiu
R=golang-codereviews, ruiu
CC=golang-codereviews
https://golang.org/cl/108150043
This commit is contained in:
Josh Bleecher Snyder 2014-06-26 13:00:47 -07:00
parent 07f6f313a9
commit 548dece8f3

View File

@ -1069,8 +1069,11 @@ func makeBenchInputHard() string {
"hello", "world", "hello", "world",
} }
x := make([]byte, 0, 1<<20) x := make([]byte, 0, 1<<20)
for len(x) < 1<<20 { for {
i := rand.Intn(len(tokens)) i := rand.Intn(len(tokens))
if len(x)+len(tokens[i]) >= 1<<20 {
break
}
x = append(x, tokens[i]...) x = append(x, tokens[i]...)
} }
return string(x) return string(x)