]> Cypherpunks repositories - gostls13.git/commitdiff
strings: avoid pointless slice growth in makeBenchInputHard
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 26 Jun 2014 20:00:47 +0000 (13:00 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 26 Jun 2014 20:00:47 +0000 (13:00 -0700)
LGTM=ruiu
R=golang-codereviews, ruiu
CC=golang-codereviews
https://golang.org/cl/108150043

src/pkg/strings/strings_test.go

index 95102b56fa5d5ca6119d565dd20d1a6099726507..27c0314fe80010d1880cbd2058104b3925e74fe0 100644 (file)
@@ -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)