mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: pre-allocate slices in PacketBuffer.AsSlices()
PiperOrigin-RevId: 615561646
This commit is contained in:
committed by
gVisor bot
parent
09f56c1f1e
commit
d25ba02fee
@@ -280,7 +280,8 @@ func (pk *PacketBuffer) Data() PacketData {
|
||||
// Note that AsSlices can allocate a lot. In hot paths it may be preferable to
|
||||
// iterate over a PacketBuffer's data via AsViewList.
|
||||
func (pk *PacketBuffer) AsSlices() [][]byte {
|
||||
var views [][]byte
|
||||
vl := pk.buf.AsViewList()
|
||||
views := make([][]byte, 0, vl.Len())
|
||||
offset := pk.headerOffset()
|
||||
pk.buf.SubApply(offset, int(pk.buf.Size())-offset, func(v *buffer.View) {
|
||||
views = append(views, v.AsSlice())
|
||||
|
||||
Reference in New Issue
Block a user