summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorBert Muthalaly <stijlist@google.com>2018-09-05 16:46:47 -0700
committerShentubot <shentubot@google.com>2018-09-05 16:47:51 -0700
commitb3b66dbd1f7f1d5411fd1f7ea76fc5ea7027ec35 (patch)
tree8637360eee1819c15b931ba82ca346638fcff64b /pkg
parent12aef686af3f37029e619602286f00a40144c52d (diff)
Enable constructing a Prependable from a View without allocating.
PiperOrigin-RevId: 211722525 Change-Id: Ie73753fd09d67d6a2ce70cfe2d4ecf7275f09ce0
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/buffer/prependable.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/tcpip/buffer/prependable.go b/pkg/tcpip/buffer/prependable.go
index d2b26cf47..5af3ff114 100644
--- a/pkg/tcpip/buffer/prependable.go
+++ b/pkg/tcpip/buffer/prependable.go
@@ -32,6 +32,15 @@ func NewPrependable(size int) Prependable {
return Prependable{buf: NewView(size), usedIdx: size}
}
+// NewPrependableFromView creates an entirely-used Prependable from a View.
+//
+// NewPrependableFromView takes ownership of v. Note that since the entire
+// prependable is used, further attempts to call Prepend will note that size >
+// p.usedIdx and return nil.
+func NewPrependableFromView(v View) Prependable {
+ return Prependable{buf: v, usedIdx: 0}
+}
+
// Prepend reserves the requested space in front of the buffer, returning a
// slice that represents the reserved space.
func (p *Prependable) Prepend(size int) []byte {