Add buffer.LenMulti

This commit is contained in:
世界 2022-10-06 16:18:21 +08:00
parent 8dcfcc6959
commit c4e9bf11fa
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 23 additions and 12 deletions

View file

@ -321,18 +321,6 @@ func (b *Buffer) Release() {
*b = Buffer{closed: true}
}
func ReleaseMulti(buffers []*Buffer) {
for _, buffer := range buffers {
buffer.Release()
}
}
func ToSliceMulti(buffers []*Buffer) [][]byte {
return common.Map(buffers, func(it *Buffer) []byte {
return it.Bytes()
})
}
func (b *Buffer) Cut(start int, end int) *Buffer {
b.start += start
b.end = len(b.data) - end

23
common/buf/multi.go Normal file
View file

@ -0,0 +1,23 @@
package buf
import "github.com/sagernet/sing/common"
func LenMulti(buffers []*Buffer) int {
var n int
for _, buffer := range buffers {
n += buffer.Len()
}
return n
}
func ToSliceMulti(buffers []*Buffer) [][]byte {
return common.Map(buffers, func(it *Buffer) []byte {
return it.Bytes()
})
}
func ReleaseMulti(buffers []*Buffer) {
for _, buffer := range buffers {
buffer.Release()
}
}