From 995fb0319eda217242fac8f2e11b576b7b7f79a9 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 25 Mar 2016 21:11:33 -0700 Subject: cmd/compile: fix stringtoslicebytetmp optimization Fixes #14973. Change-Id: Iea68c9deca9429bde465c9ae05639209fe0ccf72 Reviewed-on: https://go-review.googlesource.com/21175 Reviewed-by: Brad Fitzpatrick --- src/runtime/string_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/runtime/string_test.go') diff --git a/src/runtime/string_test.go b/src/runtime/string_test.go index 292d5595e3..ee9709e87d 100644 --- a/src/runtime/string_test.go +++ b/src/runtime/string_test.go @@ -10,6 +10,10 @@ import ( "testing" ) +// Strings and slices that don't escape and fit into tmpBuf are stack allocated, +// which defeats using AllocsPerRun to test other optimizations. +const sizeNoStack = 100 + func BenchmarkCompareStringEqual(b *testing.B) { bytes := []byte("Hello Gophers!") s1, s2 := string(bytes), string(bytes) @@ -158,7 +162,7 @@ func TestGostringnocopy(t *testing.T) { } func TestCompareTempString(t *testing.T) { - s := "foo" + s := strings.Repeat("x", sizeNoStack) b := []byte(s) n := testing.AllocsPerRun(1000, func() { if string(b) != s { @@ -221,7 +225,7 @@ func TestIntStringAllocs(t *testing.T) { } func TestRangeStringCast(t *testing.T) { - s := "abc" + s := strings.Repeat("x", sizeNoStack) n := testing.AllocsPerRun(1000, func() { for i, c := range []byte(s) { if c != s[i] { -- cgit v1.3-5-g9baa