This returns the pool number that will give a buffer of at least 'i' bytes.
(i int)
| 26 | // This returns the pool number that will give a buffer of |
| 27 | // at least 'i' bytes. |
| 28 | func poolNum(i int) int { |
| 29 | // TODO(pquerna): convert to log2 w/ bsr asm instruction: |
| 30 | // <https://groups.google.com/forum/#!topic/golang-nuts/uAb5J1_y7ns> |
| 31 | if i <= 64 { |
| 32 | return 0 |
| 33 | } else if i <= 128 { |
| 34 | return 1 |
| 35 | } else if i <= 256 { |
| 36 | return 2 |
| 37 | } else if i <= 512 { |
| 38 | return 3 |
| 39 | } else if i <= 1024 { |
| 40 | return 4 |
| 41 | } else if i <= 2048 { |
| 42 | return 5 |
| 43 | } else if i <= 4096 { |
| 44 | return 6 |
| 45 | } else if i <= 8192 { |
| 46 | return 7 |
| 47 | } else if i <= 16384 { |
| 48 | return 8 |
| 49 | } else if i <= 32768 { |
| 50 | return 9 |
| 51 | } else if i <= 65536 { |
| 52 | return 10 |
| 53 | } else if i <= 131072 { |
| 54 | return 11 |
| 55 | } else if i <= 262144 { |
| 56 | return 12 |
| 57 | } else if i <= 524288 { |
| 58 | return 13 |
| 59 | } else { |
| 60 | return -1 |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Send a buffer to the Pool to reuse for other instances. |
| 65 | // You may no longer utilize the content of the buffer, since it may be used |