mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:24:03 +03:00
Cleanup pools from wrappes
This commit is contained in:
@@ -42,8 +42,7 @@ type wrapperMtprotoFrame struct {
|
||||
}
|
||||
|
||||
func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen
|
||||
buf := acquireMtprotoFrameBytesBuffer()
|
||||
defer releaseMtprotoFrameBytesBuffer(buf)
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
sum := crc32.NewIEEE()
|
||||
writer := io.MultiWriter(buf, sum)
|
||||
@@ -114,8 +113,7 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
|
||||
messageLength := 4 + 4 + len(p) + 4
|
||||
paddingLength := (aes.BlockSize - messageLength%aes.BlockSize) % aes.BlockSize
|
||||
|
||||
buf := acquireMtprotoFrameBytesBuffer()
|
||||
defer releaseMtprotoFrameBytesBuffer(buf)
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, uint32(messageLength)) // nolint: errcheck
|
||||
binary.Write(buf, binary.LittleEndian, w.writeSeqNo) // nolint: errcheck
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
poolMtprotoFrameBytesBuffer = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &bytes.Buffer{}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func acquireMtprotoFrameBytesBuffer() *bytes.Buffer {
|
||||
return poolMtprotoFrameBytesBuffer.Get().(*bytes.Buffer)
|
||||
}
|
||||
|
||||
func releaseMtprotoFrameBytesBuffer(buf *bytes.Buffer) {
|
||||
buf.Reset()
|
||||
poolMtprotoFrameBytesBuffer.Put(buf)
|
||||
}
|
||||
Reference in New Issue
Block a user