mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #27606 from stevvooe/no-pool-pointer
pkg/pool: no need for double pointer for sync.Pool
This commit is contained in:
commit
2e742b0221
1 changed files with 12 additions and 15 deletions
|
@ -19,30 +19,26 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// BufioReader32KPool is a pool which returns bufio.Reader with a 32K buffer.
|
// BufioReader32KPool is a pool which returns bufio.Reader with a 32K buffer.
|
||||||
BufioReader32KPool *BufioReaderPool
|
BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K)
|
||||||
// BufioWriter32KPool is a pool which returns bufio.Writer with a 32K buffer.
|
// BufioWriter32KPool is a pool which returns bufio.Writer with a 32K buffer.
|
||||||
BufioWriter32KPool *BufioWriterPool
|
BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K)
|
||||||
)
|
)
|
||||||
|
|
||||||
const buffer32K = 32 * 1024
|
const buffer32K = 32 * 1024
|
||||||
|
|
||||||
// BufioReaderPool is a bufio reader that uses sync.Pool.
|
// BufioReaderPool is a bufio reader that uses sync.Pool.
|
||||||
type BufioReaderPool struct {
|
type BufioReaderPool struct {
|
||||||
pool *sync.Pool
|
pool sync.Pool
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K)
|
|
||||||
BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBufioReaderPoolWithSize is unexported because new pools should be
|
// newBufioReaderPoolWithSize is unexported because new pools should be
|
||||||
// added here to be shared where required.
|
// added here to be shared where required.
|
||||||
func newBufioReaderPoolWithSize(size int) *BufioReaderPool {
|
func newBufioReaderPoolWithSize(size int) *BufioReaderPool {
|
||||||
pool := &sync.Pool{
|
return &BufioReaderPool{
|
||||||
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
|
pool: sync.Pool{
|
||||||
|
New: func() interface{} { return bufio.NewReaderSize(nil, size) },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return &BufioReaderPool{pool: pool}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns a bufio.Reader which reads from r. The buffer size is that of the pool.
|
// 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
|
||||||
|
|
||||||
// BufioWriterPool is a bufio writer that uses sync.Pool.
|
// BufioWriterPool is a bufio writer that uses sync.Pool.
|
||||||
type BufioWriterPool struct {
|
type BufioWriterPool struct {
|
||||||
pool *sync.Pool
|
pool sync.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBufioWriterPoolWithSize is unexported because new pools should be
|
// newBufioWriterPoolWithSize is unexported because new pools should be
|
||||||
// added here to be shared where required.
|
// added here to be shared where required.
|
||||||
func newBufioWriterPoolWithSize(size int) *BufioWriterPool {
|
func newBufioWriterPoolWithSize(size int) *BufioWriterPool {
|
||||||
pool := &sync.Pool{
|
return &BufioWriterPool{
|
||||||
New: func() interface{} { return bufio.NewWriterSize(nil, size) },
|
pool: sync.Pool{
|
||||||
|
New: func() interface{} { return bufio.NewWriterSize(nil, size) },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return &BufioWriterPool{pool: pool}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns a bufio.Writer which writes to w. The buffer size is that of the pool.
|
// Get returns a bufio.Writer which writes to w. The buffer size is that of the pool.
|
||||||
|
|
Loading…
Add table
Reference in a new issue