mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-29 10:36:31 +00:00
33 lines
491 B
Go
33 lines
491 B
Go
|
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)
|
||
|
}
|