From 5ef65a036f9c5254313d3e123b3fe6c4b6bcad6e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 21 Nov 2017 11:51:54 -0800 Subject: [PATCH] make ByteSlicePool a *Pool, not a Pool. This way, copying it won't copy the underlying pool. Also, initialize it immediately instead of in an `init` function to ensure that it's fully initialized immediately. --- pool.go | 8 +++----- pool_test.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pool.go b/pool.go index 2c8681e..b913431 100644 --- a/pool.go +++ b/pool.go @@ -26,12 +26,10 @@ import ( ) // ByteSlicePool is a static Pool for reusing byteslices of various sizes. -var ByteSlicePool Pool - -func init() { - ByteSlicePool.New = func(length int) interface{} { +var ByteSlicePool = &Pool{ + New: func(length int) interface{} { return make([]byte, length) - } + }, } // MaxLength is the maximum length of an element that can be added to the Pool. diff --git a/pool_test.go b/pool_test.go index 9aaf32f..cf019c6 100644 --- a/pool_test.go +++ b/pool_test.go @@ -162,7 +162,7 @@ func TestPoolStressByteSlicePool(t *testing.T) { if testing.Short() { N /= 100 } - p := &ByteSlicePool + p := ByteSlicePool done := make(chan bool) errs := make(chan error) for i := 0; i < P; i++ { -- GitLab