1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-26 22:00:27 +08:00

optimize(gold): apply more buffer pools

This commit is contained in:
源文雨
2024-07-15 01:22:12 +09:00
parent 32af3ce142
commit 17e1f6cac9
8 changed files with 152 additions and 71 deletions

View File

@@ -1,6 +1,10 @@
package head
import "sync"
import (
"sync"
"github.com/fumiama/WireGold/helper"
)
var packetPool = sync.Pool{
New: func() interface{} {
@@ -16,6 +20,12 @@ func SelectPacket() *Packet {
// PutPacket 将 Packet 放回池中
func PutPacket(p *Packet) {
p.idxdatsz = 0
p.Data = nil
if p.buffered {
helper.PutBytes(p.data)
p.buffered = false
}
p.a, p.b = 0, 0
p.data = nil
p.rembytes = 0
packetPool.Put(p)
}