Skip to content

Commit 836f347

Browse files
committed
pkg/pool: no need for double pointer for sync.Pool
Signed-off-by: Stephen J Day <stephen.day@docker.com>
1 parent 13fd75c commit 836f347

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pkg/pools/pools.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,26 @@ import (
1919

2020
var (
2121
// BufioReader32KPool is a pool which returns bufio.Reader with a 32K buffer.
22-
BufioReader32KPool *BufioReaderPool
22+
BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K)
2323
// BufioWriter32KPool is a pool which returns bufio.Writer with a 32K buffer.
24-
BufioWriter32KPool *BufioWriterPool
24+
BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K)
2525
)
2626

2727
const buffer32K = 32 * 1024
2828

2929
// BufioReaderPool is a bufio reader that uses sync.Pool.
3030
type BufioReaderPool struct {
31-
pool *sync.Pool
32-
}
33-
34-
func init() {
35-
BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K)
36-
BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K)
31+
pool sync.Pool
3732
}
3833

3934
// newBufioReaderPoolWithSize is unexported because new pools should be
4035
// added here to be shared where required.
4136
func newBufioReaderPoolWithSize(size int) *BufioReaderPool {
42-
pool := &sync.Pool{
43-
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
37+
return &BufioReaderPool{
38+
pool: sync.Pool{
39+
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
40+
},
4441
}
45-
return &BufioReaderPool{pool: pool}
4642
}
4743

4844
// Get returns a bufio.Reader which reads from r. The buffer size is that of the pool.
@@ -80,16 +76,17 @@ func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Rea
8076

8177
// BufioWriterPool is a bufio writer that uses sync.Pool.
8278
type BufioWriterPool struct {
83-
pool *sync.Pool
79+
pool sync.Pool
8480
}
8581

8682
// newBufioWriterPoolWithSize is unexported because new pools should be
8783
// added here to be shared where required.
8884
func newBufioWriterPoolWithSize(size int) *BufioWriterPool {
89-
pool := &sync.Pool{
90-
New: func() interface{} { return bufio.NewWriterSize(nil, size) },
85+
return &BufioWriterPool{
86+
pool: sync.Pool{
87+
New: func() interface{} { return bufio.NewWriterSize(nil, size) },
88+
},
9189
}
92-
return &BufioWriterPool{pool: pool}
9390
}
9491

9592
// Get returns a bufio.Writer which writes to w. The buffer size is that of the pool.

0 commit comments

Comments
 (0)