diff options
author | Ian Gudger <igudger@google.com> | 2018-11-21 18:09:22 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-11-21 18:11:13 -0800 |
commit | 1918563525662d6645ec921e61aa7e6da92af0dd (patch) | |
tree | 55e6b8da381c77b1bcdce5678e97562372ee1199 /pkg/tcpip/buffer/view.go | |
parent | eaac94d91c28b745c51c33dd352ed9bfdd671b8c (diff) |
Make ToView non-allocating for single VectorizedViews containing a single View
PiperOrigin-RevId: 222483471
Change-Id: I6720690b20167dd541fdfa5218eba7c9f7483347
Diffstat (limited to 'pkg/tcpip/buffer/view.go')
-rw-r--r-- | pkg/tcpip/buffer/view.go | 6 |
1 files changed, 6 insertions, 0 deletions
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...) |