| 33 | } |
| 34 | |
| 35 | func (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 | |
| 53 | func (sp *byteSlicePools) reuseSlice(s *[]byte) { |
| 54 | index := int(math.Floor(math.Log2(float64(cap(*s))))) - minPoolSizePower |