diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go new file mode 100644 index 00000000..85d96a3f --- /dev/null +++ b/internal/buffer/buffer.go @@ -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) + }, +}