internal/buffer: initial implementation of the package

This commit is contained in:
Panagiotis Siatras 2022-03-22 18:36:57 +02:00
parent e82b21c1cb
commit 2fd84227f0
No known key found for this signature in database
GPG key ID: 529695F03A572804

23
internal/buffer/buffer.go Normal file
View file

@ -0,0 +1,23 @@
// Package buffer implements a reusable buffer pool.
package buffer
import (
"bytes"
"sync"
)
func Get() *bytes.Buffer {
return pool.Get().(*bytes.Buffer)
}
func Put(b *bytes.Buffer) {
b.Reset()
pool.Put(b)
}
var pool = sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}