From: Josh Bleecher Snyder Date: Thu, 26 Jun 2014 20:00:47 +0000 (-0700) Subject: strings: avoid pointless slice growth in makeBenchInputHard X-Git-Tag: go1.4beta1~1211 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=548dece8f332fdfb55b78ebd678cb8f51207be95;p=gostls13.git strings: avoid pointless slice growth in makeBenchInputHard LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/108150043 --- 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)