mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-27 08:00:00 -07:00
* replace bencode calls in http response with static generated values * move bytepool to shared folder * change receivers for `Scrapes` and `RequestAddresses` (bored of compile warnings)
28 lines
580 B
Go
28 lines
580 B
Go
package bytepool
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
// ByteBufferPool is a cached pool of reusable byte buffers.
|
|
type ByteBufferPool struct {
|
|
sync.Pool
|
|
}
|
|
|
|
// NewBufferPool allocates a new ByteBufferPool.
|
|
func NewBufferPool() *ByteBufferPool {
|
|
return &ByteBufferPool{sync.Pool{New: func() any { return new(bytes.Buffer) }}}
|
|
}
|
|
|
|
// Get returns a bytes.Buffer from the pool.
|
|
func (bbp *ByteBufferPool) Get() *bytes.Buffer {
|
|
return bbp.Pool.Get().(*bytes.Buffer)
|
|
}
|
|
|
|
// Put returns bytes.Buffer to the pool.
|
|
func (bbp *ByteBufferPool) Put(b *bytes.Buffer) {
|
|
b.Reset()
|
|
bbp.Pool.Put(b)
|
|
}
|