mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-12 10:27:28 -06:00
add git.iim.gay/grufwub/go-store for storage backend, replacing blob.Storage
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
parent
ab32ce642b
commit
e43a46e982
89 changed files with 9372 additions and 240 deletions
44
vendor/git.iim.gay/grufwub/go-store/util/pools.go
vendored
Normal file
44
vendor/git.iim.gay/grufwub/go-store/util/pools.go
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"git.iim.gay/grufwub/fastpath"
|
||||
"git.iim.gay/grufwub/go-bufpool"
|
||||
"git.iim.gay/grufwub/go-bytes"
|
||||
)
|
||||
|
||||
// pathBuilderPool is the global fastpath.Builder pool, we implement
|
||||
// our own here instead of using fastpath's default one because we
|
||||
// don't want to deal with fastpath's sync.Once locks on every Acquire/Release
|
||||
var pathBuilderPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
pb := fastpath.NewBuilder(make([]byte, 0, 512))
|
||||
return &pb
|
||||
},
|
||||
}
|
||||
|
||||
// AcquirePathBuilder returns a reset fastpath.Builder instance
|
||||
func AcquirePathBuilder() *fastpath.Builder {
|
||||
return pathBuilderPool.Get().(*fastpath.Builder)
|
||||
}
|
||||
|
||||
// ReleasePathBuilder resets and releases provided fastpath.Builder instance to global pool
|
||||
func ReleasePathBuilder(pb *fastpath.Builder) {
|
||||
pb.Reset()
|
||||
pathBuilderPool.Put(pb)
|
||||
}
|
||||
|
||||
// bufferPool is the global BufferPool, we implement this here
|
||||
// so we can share allocations across whatever libaries need them.
|
||||
var bufferPool = bufpool.BufferPool{}
|
||||
|
||||
// AcquireBuffer returns a reset bytes.Buffer with at least requested capacity
|
||||
func AcquireBuffer(cap int) *bytes.Buffer {
|
||||
return bufferPool.Get(cap)
|
||||
}
|
||||
|
||||
// ReleaseBuffer resets and releases provided bytes.Buffer to global BufferPool
|
||||
func ReleaseBuffer(buf *bytes.Buffer) {
|
||||
bufferPool.Put(buf)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue