mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Cleanup pools from wrappes
This commit is contained in:
@@ -88,9 +88,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
|
||||
return nil
|
||||
case packetLength < clientAbridgedLargePacketLength:
|
||||
length24 := utils.ToUint24(uint32(packetLength))
|
||||
|
||||
buf := acquireClientBytesBuffer()
|
||||
defer releaseClientBytesBuffer(buf)
|
||||
buf := bytes.Buffer{}
|
||||
|
||||
buf.WriteByte(byte(clientAbridgedSmallPacketLength))
|
||||
buf.Write(length24[:])
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package packetack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
@@ -34,10 +35,9 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c
|
||||
return nil
|
||||
}
|
||||
|
||||
buf := acquireClientBytesBuffer()
|
||||
defer releaseClientBytesBuffer(buf)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
paddingLength := rand.Intn(4)
|
||||
|
||||
buf.Grow(4 + len(packet) + paddingLength)
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, uint32(len(packet)+paddingLength)) // nolint: errcheck
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package packetack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
poolClientBytesBuffer = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &bytes.Buffer{}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func acquireClientBytesBuffer() *bytes.Buffer {
|
||||
return poolClientBytesBuffer.Get().(*bytes.Buffer)
|
||||
}
|
||||
|
||||
func releaseClientBytesBuffer(buf *bytes.Buffer) {
|
||||
buf.Reset()
|
||||
poolClientBytesBuffer.Put(buf)
|
||||
}
|
||||
Reference in New Issue
Block a user