MCPcopy Create free account
hub / github.com/cortexproject/cortex / getSlice

Method getSlice

pkg/cortexpb/slicesPool.go:35–51  ·  view source on GitHub ↗
(size int)

Source from the content-addressed store, hash-verified

33}
34
35func (sp *byteSlicePools) getSlice(size int) *[]byte {
36 index := int(math.Ceil(math.Log2(float64(size)))) - minPoolSizePower
37
38 if index >= len(sp.pools) {
39 buf := make([]byte, size)
40 return &buf
41 }
42
43 // if the size is < than the minPoolSizePower we return an array from the first pool
44 if index < 0 {
45 index = 0
46 }
47
48 s := sp.pools[index].Get().(*[]byte)
49 *s = (*s)[:size]
50 return s
51}
52
53func (sp *byteSlicePools) reuseSlice(s *[]byte) {
54 index := int(math.Floor(math.Log2(float64(cap(*s))))) - minPoolSizePower

Callers 4

TestFuzzyByteSlicePoolsFunction · 0.80
MarshalMethod · 0.80
MarshalMethod · 0.80

Calls 1

GetMethod · 0.65

Tested by 2

TestFuzzyByteSlicePoolsFunction · 0.64