summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-store/v2/util/pool.go
blob: ec5b501fed77fc5f691fa863506bd517b2471b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package util

import (
	"sync"

	"codeberg.org/gruf/go-fastpath/v2"
)

// pathBuilderPool is the global fastpath.Builder pool.
var pathBuilderPool = sync.Pool{
	New: func() any {
		return &fastpath.Builder{B: make([]byte, 0, 512)}
	},
}

// GetPathBuilder fetches a fastpath.Builder object from the pool.
func GetPathBuilder() *fastpath.Builder {
	pb, _ := pathBuilderPool.Get().(*fastpath.Builder)
	return pb
}

// PutPathBuilder places supplied fastpath.Builder back in the pool.
func PutPathBuilder(pb *fastpath.Builder) {
	pb.Reset()
	pathBuilderPool.Put(pb)
}