aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2014-06-26 13:00:47 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2014-06-26 13:00:47 -0700
commit548dece8f332fdfb55b78ebd678cb8f51207be95 (patch)
tree9b2ad04c449cb896cad2027ca5922c603f5967a4 /src/pkg/strings
parent07f6f313a90b264377f8a9ecc4fadfe13bfff633 (diff)
downloadgo-548dece8f332fdfb55b78ebd678cb8f51207be95.tar.xz
strings: avoid pointless slice growth in makeBenchInputHard
LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/108150043
Diffstat (limited to 'src/pkg/strings')
-rw-r--r--src/pkg/strings/strings_test.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go
index 95102b56fa..27c0314fe8 100644
--- a/src/pkg/strings/strings_test.go
+++ b/src/pkg/strings/strings_test.go
@@ -1069,8 +1069,11 @@ func makeBenchInputHard() string {
"hello", "world",
}
x := make([]byte, 0, 1<<20)
- for len(x) < 1<<20 {
+ for {
i := rand.Intn(len(tokens))
+ if len(x)+len(tokens[i]) >= 1<<20 {
+ break
+ }
x = append(x, tokens[i]...)
}
return string(x)