mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 09:35:00 +09:00
34 lines
443 B
Go
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
|
|
}
|