fermentord/vendor/github.com/mgutz/logxi/v1/pool.go
Søren Rasmussen 07a23c1845
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Upgrade to go 1.20 and add vendor catalog
2023-04-22 10:37:23 +02:00

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)
}