1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-10-13 04:24:03 -04:00

remove use of buf.NewSize()

This commit is contained in:
Darien Raymond
2018-08-16 12:05:33 +02:00
parent 053fc38d38
commit fdb3a7b57d
17 changed files with 149 additions and 122 deletions

View File

@@ -2,6 +2,13 @@ package buf
import (
"io"
"v2ray.com/core/common/bytespool"
)
const (
// Size of a regular buffer.
Size = 2048
)
// Supplier is a writer that writes contents into the given buffer.
@@ -11,8 +18,7 @@ type Supplier func([]byte) (int, error)
// the buffer into an internal buffer pool, in order to recreate a buffer more
// quickly.
type Buffer struct {
v []byte
v []byte
start int32
end int32
}
@@ -22,10 +28,9 @@ func (b *Buffer) Release() {
if b == nil || b.v == nil {
return
}
freeBytes(b.v)
bytespool.Free(b.v)
b.v = nil
b.start = 0
b.end = 0
b.Clear()
}
// Clear clears the content of the buffer, results an empty buffer with
@@ -167,13 +172,6 @@ func (b *Buffer) String() string {
// New creates a Buffer with 0 length and 2K capacity.
func New() *Buffer {
return &Buffer{
v: pool[0].Get().([]byte),
}
}
// NewSize creates and returns a buffer with 0 length and at least the given capacity. Capacity must be positive.
func NewSize(capacity int32) *Buffer {
return &Buffer{
v: newBytes(capacity),
v: bytespool.Alloc(Size),
}
}