(size int)
| 31 | } |
| 32 | |
| 33 | func (p *bufferPool) Get(size int) []byte { |
| 34 | // Too big, isn't pooled |
| 35 | if size > MaxBlockSize { |
| 36 | p.skips.Add(1) |
| 37 | return make([]byte, size) |
| 38 | } |
| 39 | |
| 40 | // Try the fitting and all bigger pools |
| 41 | bkt := getBucketForLen(size) |
| 42 | for j := bkt; j < len(BlockSizes); j++ { |
| 43 | if intf := p.pools[j].Get(); intf != nil { |
| 44 | p.hits[j].Add(1) |
| 45 | bs := *intf.(*[]byte) |
| 46 | return bs[:size] |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | p.misses.Add(1) |
| 51 | |
| 52 | // All pools are empty, must allocate. For very small slices where we |
| 53 | // didn't have a block to reuse, just allocate a small slice instead of |
| 54 | // a large one. We won't be able to reuse it, but avoid some overhead. |
| 55 | if size < MinBlockSize/64 { |
| 56 | return make([]byte, size) |
| 57 | } |
| 58 | return make([]byte, BlockSizes[bkt])[:size] |
| 59 | } |
| 60 | |
| 61 | // Put makes the given byte slice available again in the global pool. |
| 62 | // You must only Put() slices that were returned by Get(). |
nothing calls this directly
no test coverage detected