1
mirror of https://github.com/jlelse/GoBlog synced 2024-06-02 04:34:28 +00:00
GoBlog/pkgs/builderpool/builderPool.go
Jan-Lukas Else 720fc62919 Create and use a strings.Builder pool
This will probably make no big difference, but let's give it a try
2023-01-24 16:49:33 +01:00

24 lines
322 B
Go

package builderpool
import (
"strings"
"sync"
)
var builderPool = sync.Pool{
New: func() any {
return new(strings.Builder)
},
}
func Get() *strings.Builder {
return builderPool.Get().(*strings.Builder)
}
func Put(bufs ...*strings.Builder) {
for _, buf := range bufs {
buf.Reset()
builderPool.Put(buf)
}
}