2021-11-13 11:29:08 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:01:53 +00:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"codeberg.org/gruf/go-fastpath/v2"
|
2021-11-13 11:29:08 +00:00
|
|
|
)
|
|
|
|
|
2022-11-05 11:10:19 +00:00
|
|
|
// pathBuilderPool is the global fastpath.Builder pool.
|
2022-11-28 09:01:53 +00:00
|
|
|
var pathBuilderPool = sync.Pool{
|
|
|
|
New: func() any {
|
|
|
|
return &fastpath.Builder{B: make([]byte, 0, 512)}
|
|
|
|
},
|
|
|
|
}
|
2021-11-13 11:29:08 +00:00
|
|
|
|
2022-11-05 11:10:19 +00:00
|
|
|
// GetPathBuilder fetches a fastpath.Builder object from the pool.
|
2021-11-13 11:29:08 +00:00
|
|
|
func GetPathBuilder() *fastpath.Builder {
|
2022-11-28 09:01:53 +00:00
|
|
|
pb, _ := pathBuilderPool.Get().(*fastpath.Builder)
|
|
|
|
return pb
|
2021-11-13 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-05 11:10:19 +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)
|
|
|
|
}
|