diff options
Diffstat (limited to 'vendor/git.iim.gay/grufwub/fastpath/pool.go')
-rw-r--r-- | vendor/git.iim.gay/grufwub/fastpath/pool.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/git.iim.gay/grufwub/fastpath/pool.go b/vendor/git.iim.gay/grufwub/fastpath/pool.go new file mode 100644 index 000000000..047485476 --- /dev/null +++ b/vendor/git.iim.gay/grufwub/fastpath/pool.go @@ -0,0 +1,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) +} |