mirror of
https://github.com/nadoo/glider.git
synced 2026-11-23 23:49:41 +08:00
general: optimize codes
This commit is contained in:
1 parent
3c509f8b7a
commit
8f661a67a4
15 files changed
+35
-37
No files matched your search
@@ -7,7 +7,8 @@ import (
|
||||
|
||||
const (
|
||||
// number of pools.
|
||||
num = 17 // pool sizes: 1<<0 ~ 1<<16 bytes, (1Byte~64KBytes).
|
||||
// pool sizes: [1<<0 ~ 1<<(num-1)] bytes, [1B~64KB].
|
||||
num = 17
|
||||
maxsize = 1 << (num - 1)
|
||||
)
|
||||
|
||||
@@ -26,9 +27,10 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetBuffer gets a buffer from pool, size should in range: [1, 65536], otherwise, this function will call make([]byte, size) directly.
|
||||
// GetBuffer gets a buffer from pool, size should in range: [1, 65536],
|
||||
// otherwise, this function will call make([]byte, size) directly.
|
||||
func GetBuffer(size int) []byte {
|
||||
if size >= 1 && size < maxsize {
|
||||
if size >= 1 && size <= maxsize {
|
||||
i := bits.Len32(uint32(size)) - 1
|
||||
if sizes[i] < size {
|
||||
i += 1
|
||||
|
||||
Reference in new issue
Block a user