Skip to content

Commit

Permalink
Add buf.MergeMulti
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 15, 2024
1 parent 07f7dca commit d6c9d39
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions common/buf/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ func LenMulti(buffers []*Buffer) int {
return n
}

func MergeMulti(buffers []*Buffer) *Buffer {
switch len(buffers) {
case 0:
panic("empty buffers")
case 1:
return buffers[0]
default:
newBuffer := NewSize(LenMulti(buffers))
for _, buffer := range buffers {
common.Must1(newBuffer.Write(buffer.Bytes()))
buffer.Release()
}
return newBuffer
}
}

func ToSliceMulti(buffers []*Buffer) [][]byte {
return common.Map(buffers, func(it *Buffer) []byte {
return it.Bytes()
Expand Down

0 comments on commit d6c9d39

Please sign in to comment.