MCPcopy
hub / github.com/grpc/grpc-go / MaterializeToBuffer

Method MaterializeToBuffer

mem/buffer_slice.go:105–117  ·  view source on GitHub ↗

MaterializeToBuffer functions like Materialize except that it writes the data to a single Buffer pulled from the given BufferPool. As a special case, if the input BufferSlice only actually has one Buffer, this function simply increases the refcount before returning said Buffer. Freeing this buffer

(pool BufferPool)

Source from the content-addressed store, hash-verified

103// function simply increases the refcount before returning said Buffer. Freeing this
104// buffer won't release it until the BufferSlice is itself released.
105func (s BufferSlice) MaterializeToBuffer(pool BufferPool) Buffer {
106 if len(s) == 1 {
107 s[0].Ref()
108 return s[0]
109 }
110 sLen := s.Len()
111 if sLen == 0 {
112 return emptyBuffer{}
113 }
114 buf := pool.Get(sLen)
115 s.CopyTo(*buf)
116 return NewBuffer(buf, pool)
117}
118
119// Reader returns a new Reader for the input slice after taking references to
120// each underlying buffer.

Callers 4

newEmptyBufFunction · 0.95
compressFunction · 0.80
UnmarshalMethod · 0.80

Calls 5

LenMethod · 0.95
CopyToMethod · 0.95
NewBufferFunction · 0.85
RefMethod · 0.65
GetMethod · 0.65

Tested by 2

newEmptyBufFunction · 0.76