Enable constructing a Prependable from a View without allocating.
PiperOrigin-RevId: 211722525 Change-Id: Ie73753fd09d67d6a2ce70cfe2d4ecf7275f09ce0
This commit is contained in:
parent
12aef686af
commit
b3b66dbd1f
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue