diff --git a/src/strings/strings.go b/src/strings/strings.go index 4e21aff1bb..59f70da845 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -554,7 +554,7 @@ func Repeat(s string, count int) string { b.Grow(n) b.WriteString(s) for b.Len() < n { - if b.Len() <= n>>1 { + if b.Len() <= n/2 { b.WriteString(b.String()) } else { b.WriteString(b.String()[:n-b.Len()]) diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index e9d82bc2e6..50bac5d465 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -1647,21 +1647,16 @@ func BenchmarkSplitNMultiByteSeparator(b *testing.B) { } func BenchmarkRepeat(b *testing.B) { - b.Run("length-1", func(b *testing.B) { - for i := 0; i < b.N; i++ { - Repeat("-", 80) + s := Repeat("-", 16) + for n := 1; n <= 16; n <<= 1 { + for _, c := range []int{2, 6, 10} { + b.Run(fmt.Sprintf("length=%d-count=%d", n, c), func(b *testing.B) { + for i := 0; i < b.N; i++ { + Repeat(s[:n], c) + } + }) } - }) - b.Run("length-5", func(b *testing.B) { - for i := 0; i < b.N; i++ { - Repeat("-!@#$", 80) - } - }) - b.Run("length-10", func(b *testing.B) { - for i := 0; i < b.N; i++ { - Repeat("-!@#$abcde", 80) - } - }) + } } func BenchmarkIndexAnyASCII(b *testing.B) {