mirror of https://github.com/v2ray/v2ray-core
align large size
parent
053d03349a
commit
b3ecb9f766
|
@ -15,6 +15,10 @@ func createAllocFunc(size uint32) func() interface{} {
|
|||
}
|
||||
}
|
||||
|
||||
// The following parameters controls the size of buffer pools.
|
||||
// There are numPools pools. Starting from 2k size, the size of each pool is sizeMulti of the previous one.
|
||||
// Package buf is guaranteed to not use buffers larger than the largest pool.
|
||||
// Other packets may use larger buffers.
|
||||
const (
|
||||
numPools = 5
|
||||
sizeMulti = 4
|
||||
|
@ -23,6 +27,7 @@ const (
|
|||
var (
|
||||
pool [numPools]sync.Pool
|
||||
poolSize [numPools]uint32
|
||||
largeSize uint32
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -32,6 +37,7 @@ func init() {
|
|||
New: createAllocFunc(size),
|
||||
}
|
||||
poolSize[i] = size
|
||||
largeSize = size
|
||||
size *= sizeMulti
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ func NewBytesToBufferReader(reader io.Reader) Reader {
|
|||
}
|
||||
}
|
||||
|
||||
const xlSize = 128 * 1024
|
||||
|
||||
func (r *BytesToBufferReader) readSmall() (MultiBuffer, error) {
|
||||
b := New()
|
||||
for i := 0; i < 64; i++ {
|
||||
|
@ -55,7 +53,7 @@ func (r *BytesToBufferReader) ReadMultiBuffer() (MultiBuffer, error) {
|
|||
if nBytes > 0 {
|
||||
mb := NewMultiBufferCap(nBytes/Size + 1)
|
||||
mb.Write(r.buffer[:nBytes])
|
||||
if nBytes == len(r.buffer) && nBytes < xlSize {
|
||||
if nBytes == len(r.buffer) && nBytes < int(largeSize) {
|
||||
freeBytes(r.buffer)
|
||||
r.buffer = newBytes(uint32(nBytes) + 1)
|
||||
} else if nBytes < Size {
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestAdaptiveReader(t *testing.T) {
|
|||
|
||||
b, err = reader.ReadMultiBuffer()
|
||||
assert(err, IsNil)
|
||||
assert(b.Len(), Equals, 128*1024)
|
||||
assert(b.Len(), Equals, 512*1024)
|
||||
}
|
||||
|
||||
func TestBytesReaderWriteTo(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue