mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-10 08:17:30 -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
39
vendor/git.iim.gay/grufwub/go-bytes/pool.go
vendored
Normal file
39
vendor/git.iim.gay/grufwub/go-bytes/pool.go
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package bytes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type SizedBufferPool struct {
|
||||
pool sync.Pool
|
||||
len int
|
||||
cap int
|
||||
}
|
||||
|
||||
func (p *SizedBufferPool) Init(len, cap int) {
|
||||
p.pool.New = func() interface{} {
|
||||
buf := NewBuffer(make([]byte, len, cap))
|
||||
return &buf
|
||||
}
|
||||
p.len = len
|
||||
p.cap = cap
|
||||
}
|
||||
|
||||
func (p *SizedBufferPool) Acquire() *bytes.Buffer {
|
||||
return p.pool.Get().(*bytes.Buffer)
|
||||
}
|
||||
|
||||
func (p *SizedBufferPool) Release(buf *bytes.Buffer) {
|
||||
// If not enough cap, ignore
|
||||
if buf.Cap() < p.cap {
|
||||
return
|
||||
}
|
||||
|
||||
// Set length to expected
|
||||
buf.Reset()
|
||||
buf.Grow(p.len)
|
||||
|
||||
// Place in pool
|
||||
p.pool.Put(buf)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue