mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
07f6f313a9
commit
548dece8f3
1 changed files with 4 additions and 1 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue