mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-18 07:17:32 -05:00
fix lint warnings
This commit is contained in:
parent
b1b8cb5ef5
commit
83c4b20b6e
@ -98,17 +98,24 @@ func ReadFrom(reader io.Reader) (MultiBuffer, error) {
|
|||||||
// It returns the new address of MultiBuffer leftover, and number of bytes written into the input byte slice.
|
// It returns the new address of MultiBuffer leftover, and number of bytes written into the input byte slice.
|
||||||
func SplitBytes(mb MultiBuffer, b []byte) (MultiBuffer, int) {
|
func SplitBytes(mb MultiBuffer, b []byte) (MultiBuffer, int) {
|
||||||
totalBytes := 0
|
totalBytes := 0
|
||||||
|
endIndex := -1
|
||||||
for len(mb) > 0 {
|
for i := range mb {
|
||||||
bb := mb[0]
|
pBuffer := mb[i]
|
||||||
nBytes, _ := bb.Read(b)
|
nBytes, _ := pBuffer.Read(b)
|
||||||
totalBytes += nBytes
|
totalBytes += nBytes
|
||||||
b = b[nBytes:]
|
b = b[nBytes:]
|
||||||
if !bb.IsEmpty() {
|
if !pBuffer.IsEmpty() {
|
||||||
|
endIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
bb.Release()
|
pBuffer.Release()
|
||||||
mb = mb[1:]
|
mb[i] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if endIndex == -1 {
|
||||||
|
mb = mb[:0]
|
||||||
|
} else {
|
||||||
|
mb = mb[endIndex:]
|
||||||
}
|
}
|
||||||
|
|
||||||
return mb, totalBytes
|
return mb, totalBytes
|
||||||
|
@ -94,3 +94,16 @@ func TestMultiBufferSplitFirst(t *testing.T) {
|
|||||||
t.Error("expect empty buffer, but got ", mb.String())
|
t.Error("expect empty buffer, but got ", mb.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkSplitBytes(b *testing.B) {
|
||||||
|
var mb MultiBuffer
|
||||||
|
raw := make([]byte, Size)
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buffer := StackNew()
|
||||||
|
buffer.Extend(Size)
|
||||||
|
mb = append(mb, &buffer)
|
||||||
|
mb, _ = SplitBytes(mb, raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -48,6 +48,7 @@ type multiReader interface {
|
|||||||
Clear()
|
Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadVReader is a Reader that uses readv(2) syscall to read data.
|
||||||
type ReadVReader struct {
|
type ReadVReader struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
rawConn syscall.RawConn
|
rawConn syscall.RawConn
|
||||||
@ -55,6 +56,7 @@ type ReadVReader struct {
|
|||||||
alloc allocStrategy
|
alloc allocStrategy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReadVReader creates a new ReadVReader.
|
||||||
func NewReadVReader(reader io.Reader, rawConn syscall.RawConn) *ReadVReader {
|
func NewReadVReader(reader io.Reader, rawConn syscall.RawConn) *ReadVReader {
|
||||||
return &ReadVReader{
|
return &ReadVReader{
|
||||||
Reader: reader,
|
Reader: reader,
|
||||||
|
Loading…
Reference in New Issue
Block a user