From 1918563525662d6645ec921e61aa7e6da92af0dd Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Wed, 21 Nov 2018 18:09:22 -0800 Subject: Make ToView non-allocating for single VectorizedViews containing a single View PiperOrigin-RevId: 222483471 Change-Id: I6720690b20167dd541fdfa5218eba7c9f7483347 --- pkg/tcpip/buffer/view.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pkg/tcpip/buffer') diff --git a/pkg/tcpip/buffer/view.go b/pkg/tcpip/buffer/view.go index d8c3b0cb4..43cbb9461 100644 --- a/pkg/tcpip/buffer/view.go +++ b/pkg/tcpip/buffer/view.go @@ -132,7 +132,13 @@ func (vv VectorisedView) Size() int { } // ToView returns a single view containing the content of the vectorised view. +// +// If the vectorised view contains a single view, that view will be returned +// directly. func (vv VectorisedView) ToView() View { + if len(vv.views) == 1 { + return vv.views[0] + } u := make([]byte, 0, vv.size) for _, v := range vv.views { u = append(u, v...) -- cgit v1.2.3