summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2018-11-21 18:09:22 -0800
committerShentubot <shentubot@google.com>2018-11-21 18:11:13 -0800
commit1918563525662d6645ec921e61aa7e6da92af0dd (patch)
tree55e6b8da381c77b1bcdce5678e97562372ee1199 /pkg
parenteaac94d91c28b745c51c33dd352ed9bfdd671b8c (diff)
Make ToView non-allocating for single VectorizedViews containing a single View
PiperOrigin-RevId: 222483471 Change-Id: I6720690b20167dd541fdfa5218eba7c9f7483347
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/buffer/view.go6
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...)