sqlboiler/strmangle/buf_pool.go

28 lines
399 B
Go
Raw Permalink Normal View History

2016-08-13 09:49:39 +02:00
package strmangle
import (
"bytes"
"sync"
)
var bufPool = sync.Pool{
New: newBuffer,
}
func newBuffer() interface{} {
return &bytes.Buffer{}
}
// GetBuffer retrieves a buffer from the buffer pool
func GetBuffer() *bytes.Buffer {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
// PutBuffer back into the buffer pool
func PutBuffer(buf *bytes.Buffer) {
bufPool.Put(buf)
}