aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/bytes/buffer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/bytes/buffer_test.go')
-rw-r--r--libgo/go/bytes/buffer_test.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/libgo/go/bytes/buffer_test.go b/libgo/go/bytes/buffer_test.go
index 7626d27..fec5ef8 100644
--- a/libgo/go/bytes/buffer_test.go
+++ b/libgo/go/bytes/buffer_test.go
@@ -8,7 +8,6 @@ import (
. "bytes"
"io"
"math/rand"
- "runtime"
"testing"
"unicode/utf8"
)
@@ -495,20 +494,20 @@ func TestGrow(t *testing.T) {
x := []byte{'x'}
y := []byte{'y'}
tmp := make([]byte, 72)
- for _, startLen := range []int{0, 100, 1000, 10000, 100000} {
- xBytes := Repeat(x, startLen)
- for _, growLen := range []int{0, 100, 1000, 10000, 100000} {
+ for _, growLen := range []int{0, 100, 1000, 10000, 100000} {
+ for _, startLen := range []int{0, 100, 1000, 10000, 100000} {
+ xBytes := Repeat(x, startLen)
+
buf := NewBuffer(xBytes)
// If we read, this affects buf.off, which is good to test.
readBytes, _ := buf.Read(tmp)
- buf.Grow(growLen)
yBytes := Repeat(y, growLen)
+ allocs := testing.AllocsPerRun(100, func() {
+ buf.Grow(growLen)
+ buf.Write(yBytes)
+ })
// Check no allocation occurs in write, as long as we're single-threaded.
- var m1, m2 runtime.MemStats
- runtime.ReadMemStats(&m1)
- buf.Write(yBytes)
- runtime.ReadMemStats(&m2)
- if runtime.GOMAXPROCS(-1) == 1 && m1.Mallocs != m2.Mallocs {
+ if allocs != 0 {
t.Errorf("allocation occurred during write")
}
// Check that buffer has correct data.