Søren Rasmussen
07a23c1845
Some checks reported errors
continuous-integration/drone/push Build encountered an error
29 lines
420 B
Go
29 lines
420 B
Go
package log
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
type BufferPool struct {
|
|
sync.Pool
|
|
}
|
|
|
|
func NewBufferPool() *BufferPool {
|
|
return &BufferPool{
|
|
Pool: sync.Pool{New: func() interface{} {
|
|
b := bytes.NewBuffer(make([]byte, 128))
|
|
b.Reset()
|
|
return b
|
|
}},
|
|
}
|
|
}
|
|
|
|
func (bp *BufferPool) Get() *bytes.Buffer {
|
|
return bp.Pool.Get().(*bytes.Buffer)
|
|
}
|
|
|
|
func (bp *BufferPool) Put(b *bytes.Buffer) {
|
|
b.Reset()
|
|
bp.Pool.Put(b)
|
|
}
|