From 95b16cd805e96889f281aba2f3d1f530be9b7308 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Mon, 10 Aug 2020 13:27:23 +0300 Subject: [PATCH] Cleanup pools from tlstypes --- tlstypes/handshake.go | 11 +++++------ tlstypes/pools.go | 23 ----------------------- 2 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 tlstypes/pools.go diff --git a/tlstypes/handshake.go b/tlstypes/handshake.go index f70fc92..3775b45 100644 --- a/tlstypes/handshake.go +++ b/tlstypes/handshake.go @@ -1,6 +1,7 @@ package tlstypes import ( + "bytes" "io" "github.com/9seconds/mtg/utils" @@ -15,8 +16,7 @@ type Handshake struct { } func (h *Handshake) WriteBytes(writer io.Writer) { - packetBuf := acquireBytesBuffer() - defer releaseBytesBuffer(packetBuf) + packetBuf := bytes.Buffer{} writer.Write([]byte{byte(h.Type)}) // nolint: errcheck @@ -24,7 +24,7 @@ func (h *Handshake) WriteBytes(writer io.Writer) { packetBuf.Write(h.Random[:]) packetBuf.WriteByte(byte(len(h.SessionID))) packetBuf.Write(h.SessionID) - h.Tail.WriteBytes(packetBuf) + h.Tail.WriteBytes(&packetBuf) sizeUint24 := utils.ToUint24(uint32(packetBuf.Len())) sizeUint24Bytes := sizeUint24[:] @@ -35,10 +35,9 @@ func (h *Handshake) WriteBytes(writer io.Writer) { } func (h *Handshake) Len() int { - buf := acquireBytesBuffer() - defer releaseBytesBuffer(buf) + buf := bytes.Buffer{} - h.WriteBytes(buf) + h.WriteBytes(&buf) return buf.Len() } diff --git a/tlstypes/pools.go b/tlstypes/pools.go deleted file mode 100644 index f51aae7..0000000 --- a/tlstypes/pools.go +++ /dev/null @@ -1,23 +0,0 @@ -package tlstypes - -import ( - "bytes" - "sync" -) - -var ( - poolBytesBuffer = sync.Pool{ - New: func() interface{} { - return &bytes.Buffer{} - }, - } -) - -func acquireBytesBuffer() *bytes.Buffer { - return poolBytesBuffer.Get().(*bytes.Buffer) -} - -func releaseBytesBuffer(buf *bytes.Buffer) { - buf.Reset() - poolBytesBuffer.Put(buf) -}