remove segment pools

pull/1524/head^2 v3.32.1
Darien Raymond 2018-07-29 03:54:24 +02:00
parent 2d4a0f23d5
commit 1ca3bb9750
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 3 additions and 28 deletions

View File

@ -1,8 +1,6 @@
package kcp package kcp
import ( import (
"sync"
"v2ray.com/core/common/buf" "v2ray.com/core/common/buf"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
@ -40,12 +38,6 @@ const (
DataSegmentOverhead = 18 DataSegmentOverhead = 18
) )
var dataSegmentPool = sync.Pool{
New: func() interface{} {
return new(DataSegment)
},
}
type DataSegment struct { type DataSegment struct {
Conv uint16 Conv uint16
Option SegmentOption Option SegmentOption
@ -59,11 +51,7 @@ type DataSegment struct {
} }
func NewDataSegment() *DataSegment { func NewDataSegment() *DataSegment {
seg := dataSegmentPool.Get().(*DataSegment) return new(DataSegment)
seg.Conv = 0
seg.timeout = 0
seg.transmit = 0
return seg
} }
func (s *DataSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { 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() { func (s *DataSegment) Release() {
s.payload.Release() s.payload.Release()
s.payload = nil s.payload = nil
dataSegmentPool.Put(s)
}
var ackSegmentPool = sync.Pool{
New: func() interface{} {
return &AckSegment{
NumberList: make([]uint32, 0, 16),
}
},
} }
type AckSegment struct { type AckSegment struct {
@ -158,9 +137,7 @@ type AckSegment struct {
const ackNumberLimit = 128 const ackNumberLimit = 128
func NewAckSegment() *AckSegment { func NewAckSegment() *AckSegment {
seg := ackSegmentPool.Get().(*AckSegment) return new(AckSegment)
seg.NumberList = seg.NumberList[:0]
return seg
} }
func (s *AckSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { 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() { func (s *AckSegment) Release() {}
ackSegmentPool.Put(s)
}
type CmdOnlySegment struct { type CmdOnlySegment struct {
Conv uint16 Conv uint16