gotosocial/vendor/codeberg.org/gruf/go-store/v2/util/pool.go

27 lines
565 B
Go
Raw Normal View History

2021-11-13 11:29:08 +00:00
package util
import (
"sync"
"codeberg.org/gruf/go-fastpath/v2"
2021-11-13 11:29:08 +00:00
)
// pathBuilderPool is the global fastpath.Builder pool.
var pathBuilderPool = sync.Pool{
New: func() any {
return &fastpath.Builder{B: make([]byte, 0, 512)}
},
}
2021-11-13 11:29:08 +00:00
// GetPathBuilder fetches a fastpath.Builder object from the pool.
2021-11-13 11:29:08 +00:00
func GetPathBuilder() *fastpath.Builder {
pb, _ := pathBuilderPool.Get().(*fastpath.Builder)
return pb
2021-11-13 11:29:08 +00:00
}
// PutPathBuilder places supplied fastpath.Builder back in the pool.
2021-11-13 11:29:08 +00:00
func PutPathBuilder(pb *fastpath.Builder) {
pb.Reset()
pathBuilderPool.Put(pb)
}