mirror of https://github.com/v2ray/v2ray-core
remove NewMultiBufferCap
parent
2364f5f280
commit
48cac1733f
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
// ReadAllToMultiBuffer reads all content from the reader into a MultiBuffer, until EOF.
|
||||
func ReadAllToMultiBuffer(reader io.Reader) (MultiBuffer, error) {
|
||||
mb := NewMultiBufferCap(128)
|
||||
mb := make(MultiBuffer, 0, 128)
|
||||
|
||||
if _, err := mb.ReadFrom(reader); err != nil {
|
||||
mb.Release()
|
||||
|
@ -38,11 +38,6 @@ func ReadAllToBytes(reader io.Reader) ([]byte, error) {
|
|||
// MultiBuffer is a list of Buffers. The order of Buffer matters.
|
||||
type MultiBuffer []*Buffer
|
||||
|
||||
// NewMultiBufferCap creates a new MultiBuffer instance.
|
||||
func NewMultiBufferCap(capacity int32) MultiBuffer {
|
||||
return MultiBuffer(make([]*Buffer, 0, capacity))
|
||||
}
|
||||
|
||||
// Append appends buffer to the end of this MultiBuffer
|
||||
func (mb *MultiBuffer) Append(buf *Buffer) {
|
||||
if buf != nil {
|
||||
|
@ -159,13 +154,13 @@ func (mb *MultiBuffer) WriteMultiBuffer(b MultiBuffer) error {
|
|||
}
|
||||
|
||||
// Len returns the total number of bytes in the MultiBuffer.
|
||||
func (mb *MultiBuffer) Len() int32 {
|
||||
func (mb MultiBuffer) Len() int32 {
|
||||
if mb == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
size := int32(0)
|
||||
for _, b := range *mb {
|
||||
for _, b := range mb {
|
||||
size += b.Len()
|
||||
}
|
||||
return size
|
||||
|
@ -200,7 +195,7 @@ func (mb MultiBuffer) String() string {
|
|||
|
||||
// SliceBySize splits the beginning of this MultiBuffer into another one, for at most size bytes.
|
||||
func (mb *MultiBuffer) SliceBySize(size int32) MultiBuffer {
|
||||
slice := NewMultiBufferCap(10)
|
||||
slice := make(MultiBuffer, 0, 10)
|
||||
sliceSize := int32(0)
|
||||
endIndex := len(*mb)
|
||||
for i, b := range *mb {
|
||||
|
|
|
@ -139,5 +139,5 @@ func (r *SingleReader) ReadMultiBuffer() (MultiBuffer, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewMultiBufferValue(b), nil
|
||||
return MultiBuffer{b}, nil
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ func (r *AuthenticationReader) readInternal(soft bool, mb *buf.MultiBuffer) erro
|
|||
|
||||
func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
const readSize = 16
|
||||
mb := buf.NewMultiBufferCap(readSize)
|
||||
mb := make(buf.MultiBuffer, 0, readSize)
|
||||
if err := r.readInternal(false, &mb); err != nil {
|
||||
mb.Release()
|
||||
return nil, err
|
||||
|
@ -277,7 +277,7 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
|||
}
|
||||
|
||||
payloadSize := buf.Size - int32(w.auth.Overhead()) - w.sizeParser.SizeBytes() - maxPadding
|
||||
mb2Write := buf.NewMultiBufferCap(int32(len(mb) + 10))
|
||||
mb2Write := make(buf.MultiBuffer, 0, len(mb)+10)
|
||||
|
||||
for {
|
||||
b := buf.New()
|
||||
|
@ -301,7 +301,7 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
|||
func (w *AuthenticationWriter) writePacket(mb buf.MultiBuffer) error {
|
||||
defer mb.Release()
|
||||
|
||||
mb2Write := buf.NewMultiBufferCap(int32(len(mb)) + 1)
|
||||
mb2Write := make(buf.MultiBuffer, 0, len(mb)+1)
|
||||
|
||||
for _, b := range mb {
|
||||
if b.IsEmpty() {
|
||||
|
|
|
@ -140,7 +140,7 @@ func NewChunkStreamWriter(sizeEncoder ChunkSizeEncoder, writer io.Writer) *Chunk
|
|||
func (w *ChunkStreamWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
const sliceSize = 8192
|
||||
mbLen := mb.Len()
|
||||
mb2Write := buf.NewMultiBufferCap(mbLen/buf.Size + mbLen/sliceSize + 2)
|
||||
mb2Write := make(buf.MultiBuffer, 0, mbLen/buf.Size+mbLen/sliceSize+2)
|
||||
|
||||
for {
|
||||
slice := mb.SliceBySize(sliceSize)
|
||||
|
|
|
@ -70,7 +70,7 @@ func writeMetaWithFrame(writer buf.Writer, meta FrameMetadata, data buf.MultiBuf
|
|||
return err
|
||||
}
|
||||
|
||||
mb2 := buf.NewMultiBufferCap(int32(len(data)) + 1)
|
||||
mb2 := make(buf.MultiBuffer, 0, len(data)+1)
|
||||
mb2.Append(frame)
|
||||
mb2.AppendMulti(data)
|
||||
return writer.WriteMultiBuffer(mb2)
|
||||
|
|
|
@ -99,7 +99,7 @@ func (c *connection) Write(b []byte) (int, error) {
|
|||
}
|
||||
|
||||
l := len(b)
|
||||
mb := buf.NewMultiBufferCap(int32(l)/buf.Size + 1)
|
||||
mb := make(buf.MultiBuffer, 0, l/buf.Size+1)
|
||||
common.Must2(mb.Write(b))
|
||||
return l, c.writer.WriteMultiBuffer(mb)
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ func (w *ReceivingWorker) ReadMultiBuffer() buf.MultiBuffer {
|
|||
return mb
|
||||
}
|
||||
|
||||
mb := buf.NewMultiBufferCap(32)
|
||||
mb := make(buf.MultiBuffer, 0, 32)
|
||||
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
|
Loading…
Reference in New Issue