summaryrefslogtreecommitdiff
path: root/vendor/git.iim.gay/grufwub/fastpath/pool.go
blob: 04748547615614e6090a38dff6a2928ae96b4850 (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
27
28
29
30
31
32
package fastpath

import "sync"

// 1/8 max unix path length
const defaultBufSize = 512

var (
	builderPool sync.Pool
	once        = sync.Once{}
)

func pool() *sync.Pool {
	once.Do(func() {
		builderPool = sync.Pool{
			New: func() interface{} {
				builder := NewBuilder(make([]byte, defaultBufSize))
				return &builder
			},
		}
	})
	return &builderPool
}

func AcquireBuilder() *Builder {
	return pool().Get().(*Builder)
}

func ReleaseBuilder(b *Builder) {
	b.Reset()
	pool().Put(b)
}