|
@@ -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
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func init() {
|
|
|
|
- BufioReader32KPool = newBufioReaderPoolWithSize(buffer32K)
|
|
|
|
- BufioWriter32KPool = newBufioWriterPoolWithSize(buffer32K)
|
|
|
|
|
|
+ pool sync.Pool
|
|
}
|
|
}
|
|
|
|
|
|
// 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{
|
|
|
|
- New: func() interface{} { return bufio.NewReaderSize(nil, size) },
|
|
|
|
|
|
+ return &BufioReaderPool{
|
|
|
|
+ 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{
|
|
|
|
- New: func() interface{} { return bufio.NewWriterSize(nil, size) },
|
|
|
|
|
|
+ return &BufioWriterPool{
|
|
|
|
+ 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.
|