1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 09:35:00 +09:00
anytype-heart/util/bufferpool/pool.go
Roman Khafizianov 6b73d0e839
GO-3538 image resize: add bufferpool
avoid double resizing
2024-05-28 16:45:18 +02:00

34 lines
443 B
Go

package bufferpool
import (
"bytes"
"sync"
)
type Pool interface {
Get() Buffer
}
func NewPool() Pool {
return &bufferPoolWrapper{pool: &sync.Pool{
New: func() interface{} {
return []byte{}
},
}}
}
type bufferPoolWrapper struct {
pool *sync.Pool
}
func (bp *bufferPoolWrapper) Get() Buffer {
b := bp.pool.Get().([]byte)
buff := &buffer{
Buffer: bytes.NewBuffer(b[:0]),
buf: b,
pool: bp.pool,
}
return buff
}