mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-12-21 02:03:19 +00:00
5004e0a9da
* fix error check of prune to allow missing files * update go-store library, add test for pruning item with db entry but no file Signed-off-by: kim <grufwub@gmail.com> * remove now-unneccessary error check Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: kim <grufwub@gmail.com>
46 lines
989 B
Go
46 lines
989 B
Go
package pools
|
|
|
|
import (
|
|
"hash"
|
|
"sync"
|
|
|
|
"codeberg.org/gruf/go-hashenc"
|
|
)
|
|
|
|
// HashEncoderPool is a pooled allocator for hashenc.HashEncoder objects.
|
|
type HashEncoderPool interface {
|
|
// Get fetches a hashenc.HashEncoder from pool
|
|
Get() hashenc.HashEncoder
|
|
|
|
// Put places supplied hashenc.HashEncoder back in pool
|
|
Put(hashenc.HashEncoder)
|
|
}
|
|
|
|
// NewHashEncoderPool returns a newly instantiated hashenc.HashEncoder pool.
|
|
func NewHashEncoderPool(hash func() hash.Hash, enc func() hashenc.Encoder) HashEncoderPool {
|
|
return &hencPool{
|
|
pool: sync.Pool{
|
|
New: func() interface{} {
|
|
return hashenc.New(hash(), enc())
|
|
},
|
|
},
|
|
size: hashenc.New(hash(), enc()).Size(),
|
|
}
|
|
}
|
|
|
|
// hencPool is our implementation of HashEncoderPool.
|
|
type hencPool struct {
|
|
pool sync.Pool
|
|
size int
|
|
}
|
|
|
|
func (p *hencPool) Get() hashenc.HashEncoder {
|
|
return p.pool.Get().(hashenc.HashEncoder)
|
|
}
|
|
|
|
func (p *hencPool) Put(henc hashenc.HashEncoder) {
|
|
if henc.Size() < p.size {
|
|
return
|
|
}
|
|
p.pool.Put(henc)
|
|
}
|