2021-03-08 16:46:23 +00:00
|
|
|
package origin
|
2020-02-24 17:06:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2021-03-08 16:46:23 +00:00
|
|
|
type bufferPool struct {
|
|
|
|
// A bufferPool must not be copied after first use.
|
2020-02-24 17:06:19 +00:00
|
|
|
// https://golang.org/pkg/sync/#Pool
|
|
|
|
buffers sync.Pool
|
|
|
|
}
|
|
|
|
|
2021-03-08 16:46:23 +00:00
|
|
|
func newBufferPool(bufferSize int) *bufferPool {
|
|
|
|
return &bufferPool{
|
2020-02-24 17:06:19 +00:00
|
|
|
buffers: sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return make([]byte, bufferSize)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 16:46:23 +00:00
|
|
|
func (p *bufferPool) Get() []byte {
|
2020-02-24 17:06:19 +00:00
|
|
|
return p.buffers.Get().([]byte)
|
|
|
|
}
|
|
|
|
|
2021-03-08 16:46:23 +00:00
|
|
|
func (p *bufferPool) Put(buf []byte) {
|
2020-02-24 17:06:19 +00:00
|
|
|
p.buffers.Put(buf)
|
|
|
|
}
|