There was an error while loading. Please reload this page.
1 parent e917fb7 commit a79722bCopy full SHA for a79722b
1 file changed
buffer/pool.go
@@ -6,6 +6,7 @@ import (
6
"io"
7
"net"
8
"sync"
9
+ "unsafe"
10
)
11
12
// PoolConfig contains configuration for the allocation and reuse strategy.
@@ -47,17 +48,19 @@ func putBuf(buf []byte) {
47
48
return
49
}
50
if c := buffers[size]; c != nil {
- c.Put(buf[:0])
51
+ c.Put(unsafe.Pointer(&buf[:1][0]))
52
53
54
55
+const maxArraySize = uint((uint64(1)<<50 - 1) & uint64(^uint(0)>>1))
56
+
57
// getBuf gets a chunk from reuse pool or creates a new one if reuse failed.
58
func getBuf(size int) []byte {
59
if size >= config.PooledSize {
60
61
v := c.Get()
62
if v != nil {
- return v.([]byte)
63
+ return (*[maxArraySize]byte)(v.(unsafe.Pointer))[:0:size]
64
65
66
0 commit comments