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

Method Slice

mem/buffers.go:187–211  ·  view source on GitHub ↗
(start, end int)

Source from the content-addressed store, hash-verified

185}
186
187func (b *buffer) Slice(start, end int) Buffer {
188 if b.rootBuf == nil {
189 panic("Cannot slice freed buffer")
190 }
191
192 data := b.data[start:end] // access the data to check slice bounds
193
194 if len(data) == 0 {
195 return emptyBuffer{}
196 }
197 if len(data) == len(b.data) {
198 b.Ref()
199 return b
200 }
201 // We are creating a new reference (view) to a portion of the root buffer's
202 // data. Therefore, we must increment the reference count of the root buffer
203 // to ensure the underlying data is not freed while this view is still in
204 // use.
205 b.rootBuf.Ref()
206 s := newBuffer()
207 s.data = data
208 s.rootBuf = b.rootBuf
209 s.refs.Store(1)
210 return s
211}
212
213func (b *buffer) split(n int) (Buffer, Buffer) {
214 if b.rootBuf == nil || b.rootBuf.refs.Add(1) <= 1 {

Callers

nothing calls this directly

Calls 3

RefMethod · 0.95
newBufferFunction · 0.70
RefMethod · 0.65

Tested by

no test coverage detected