From 1ca3bb97509161e09237da3b484e08c95d43e3b2 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sun, 29 Jul 2018 03:54:24 +0200 Subject: [PATCH] remove segment pools --- transport/internet/kcp/segment.go | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 52881e45..ce8ee09c 100755 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -1,8 +1,6 @@ package kcp import ( - "sync" - "v2ray.com/core/common/buf" "v2ray.com/core/common/serial" ) @@ -40,12 +38,6 @@ const ( DataSegmentOverhead = 18 ) -var dataSegmentPool = sync.Pool{ - New: func() interface{} { - return new(DataSegment) - }, -} - type DataSegment struct { Conv uint16 Option SegmentOption @@ -59,11 +51,7 @@ type DataSegment struct { } func NewDataSegment() *DataSegment { - seg := dataSegmentPool.Get().(*DataSegment) - seg.Conv = 0 - seg.timeout = 0 - seg.transmit = 0 - return seg + return new(DataSegment) } func (s *DataSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { @@ -135,15 +123,6 @@ func (s *DataSegment) ByteSize() int32 { func (s *DataSegment) Release() { s.payload.Release() s.payload = nil - dataSegmentPool.Put(s) -} - -var ackSegmentPool = sync.Pool{ - New: func() interface{} { - return &AckSegment{ - NumberList: make([]uint32, 0, 16), - } - }, } type AckSegment struct { @@ -158,9 +137,7 @@ type AckSegment struct { const ackNumberLimit = 128 func NewAckSegment() *AckSegment { - seg := ackSegmentPool.Get().(*AckSegment) - seg.NumberList = seg.NumberList[:0] - return seg + return new(AckSegment) } func (s *AckSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { @@ -239,9 +216,7 @@ func (s *AckSegment) Bytes() buf.Supplier { } } -func (s *AckSegment) Release() { - ackSegmentPool.Put(s) -} +func (s *AckSegment) Release() {} type CmdOnlySegment struct { Conv uint16