Clarify ownership of (*Torrent).chunkPool (#583)

Basically bind the lifetime of chunkPool to the torrent by using `sync.Pool` in lieu of `*sync.Pool`. Gives the GC ever so slightly less work to do.
This commit is contained in:
YenForYang 2021-09-09 07:27:16 -05:00 committed by GitHub
parent 10d5e6234e
commit 62c6fbc8f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -1030,7 +1030,7 @@ func (c *PeerConn) mainReadLoop() (err error) {
decoder := pp.Decoder{
R: bufio.NewReaderSize(c.r, 1<<17),
MaxLength: 256 * 1024,
Pool: t.chunkPool,
Pool: &t.chunkPool,
}
for {
var msg pp.Message

View File

@ -66,7 +66,7 @@ type Torrent struct {
// The size of chunks to request from peers over the wire. This is
// normally 16KiB by convention these days.
chunkSize pp.Integer
chunkPool *sync.Pool
chunkPool sync.Pool
// Total length of the torrent in bytes. Stored because it's not O(1) to
// get this from the info dict.
length *int64
@ -233,7 +233,7 @@ func (t *Torrent) KnownSwarm() (ks []PeerInfo) {
func (t *Torrent) setChunkSize(size pp.Integer) {
t.chunkSize = size
t.chunkPool = &sync.Pool{
t.chunkPool = sync.Pool{
New: func() interface{} {
b := make([]byte, size)
return &b