Send a buffer to the Pool to reuse for other instances. You may no longer utilize the content of the buffer, since it may be used by other goroutines.
(b []byte)
| 65 | // You may no longer utilize the content of the buffer, since it may be used |
| 66 | // by other goroutines. |
| 67 | func Pool(b []byte) { |
| 68 | if b == nil { |
| 69 | return |
| 70 | } |
| 71 | c := cap(b) |
| 72 | |
| 73 | // Our smallest buffer is 64 bytes, so we discard smaller buffers. |
| 74 | if c < 64 { |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | // We need to put the incoming buffer into the NEXT buffer, |
| 79 | // since a buffer guarantees AT LEAST the number of bytes available |
| 80 | // that is the top of this buffer. |
| 81 | // That is the reason for dividing the cap by 2, so it gets into the NEXT bucket. |
| 82 | // We add 2 to avoid rounding down if size is exactly power of 2. |
| 83 | pn := poolNum((c + 2) >> 1) |
| 84 | if pn != -1 { |
| 85 | pools[pn].Put(b[0:0]) |
| 86 | } |
| 87 | // if we didn't have a slot for this []byte, we just drop it and let the GC |
| 88 | // take care of it. |
| 89 | } |
| 90 | |
| 91 | // makeSlice allocates a slice of size n -- it will attempt to use a pool'ed |
| 92 | // instance whenever possible. |
no test coverage detected
searching dependent graphs…