Enable constructing a Prependable from a View without allocating.

PiperOrigin-RevId: 211722525
Change-Id: Ie73753fd09d67d6a2ce70cfe2d4ecf7275f09ce0
This commit is contained in:
Bert Muthalaly 2018-09-05 16:46:47 -07:00 committed by Shentubot
parent 12aef686af
commit b3b66dbd1f
1 changed files with 9 additions and 0 deletions

View File

@ -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 {