Signed-off-by: Stephen J Day <stephen.day@docker.com>
| ... | ... |
@@ -19,30 +19,26 @@ import ( |
| 19 | 19 |
|
| 20 | 20 |
var ( |
| 21 | 21 |
// BufioReader32KPool is a pool which returns bufio.Reader with a 32K buffer. |
| 22 |
- BufioReader32KPool *BufioReaderPool |
|
| 22 |
+ BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K) |
|
| 23 | 23 |
// BufioWriter32KPool is a pool which returns bufio.Writer with a 32K buffer. |
| 24 |
- BufioWriter32KPool *BufioWriterPool |
|
| 24 |
+ BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K) |
|
| 25 | 25 |
) |
| 26 | 26 |
|
| 27 | 27 |
const buffer32K = 32 * 1024 |
| 28 | 28 |
|
| 29 | 29 |
// BufioReaderPool is a bufio reader that uses sync.Pool. |
| 30 | 30 |
type BufioReaderPool struct {
|
| 31 |
- pool *sync.Pool |
|
| 32 |
-} |
|
| 33 |
- |
|
| 34 |
-func init() {
|
|
| 35 |
- BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K) |
|
| 36 |
- BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K) |
|
| 31 |
+ pool sync.Pool |
|
| 37 | 32 |
} |
| 38 | 33 |
|
| 39 | 34 |
// newBufioReaderPoolWithSize is unexported because new pools should be |
| 40 | 35 |
// added here to be shared where required. |
| 41 | 36 |
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 |
+ }, |
|
| 44 | 41 |
} |
| 45 |
- return &BufioReaderPool{pool: pool}
|
|
| 46 | 42 |
} |
| 47 | 43 |
|
| 48 | 44 |
// 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 |
| 80 | 80 |
|
| 81 | 81 |
// BufioWriterPool is a bufio writer that uses sync.Pool. |
| 82 | 82 |
type BufioWriterPool struct {
|
| 83 |
- pool *sync.Pool |
|
| 83 |
+ pool sync.Pool |
|
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
// newBufioWriterPoolWithSize is unexported because new pools should be |
| 87 | 87 |
// added here to be shared where required. |
| 88 | 88 |
func newBufioWriterPoolWithSize(size int) *BufioWriterPool {
|
| 89 |
- pool := &sync.Pool{
|
|
| 90 |
- New: func() interface{} { return bufio.NewWriterSize(nil, size) },
|
|
| 89 |
+ return &BufioWriterPool{
|
|
| 90 |
+ pool: sync.Pool{
|
|
| 91 |
+ New: func() interface{} { return bufio.NewWriterSize(nil, size) },
|
|
| 92 |
+ }, |
|
| 91 | 93 |
} |
| 92 |
- return &BufioWriterPool{pool: pool}
|
|
| 93 | 94 |
} |
| 94 | 95 |
|
| 95 | 96 |
// Get returns a bufio.Writer which writes to w. The buffer size is that of the pool. |