Skip to content

Commit 1f4bc35

Browse files
committed
rpc_util: standardize buffer pool interface to use []byte in Put method
1 parent 63a360e commit 1f4bc35

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

rpc_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interf
803803
if payInfo != nil {
804804
payInfo.uncompressedBytes = buf
805805
} else {
806-
p.recvBufferPool.Put(&buf)
806+
p.recvBufferPool.Put(buf)
807807
}
808808
return nil
809809
}

shared_buffer_pool.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type SharedBufferPool interface {
3535
Get(length int) []byte
3636

3737
// Put returns a buffer to the pool.
38-
Put(*[]byte)
38+
Put([]byte)
3939
}
4040

4141
// NewSharedBufferPool creates a simple SharedBufferPool with buckets
@@ -68,8 +68,8 @@ func (p *simpleSharedBufferPool) Get(size int) []byte {
6868
return p.pools[p.poolIdx(size)].Get(size)
6969
}
7070

71-
func (p *simpleSharedBufferPool) Put(bs *[]byte) {
72-
p.pools[p.poolIdx(cap(*bs))].Put(bs)
71+
func (p *simpleSharedBufferPool) Put(bs []byte) {
72+
p.pools[p.poolIdx(cap(bs))].Put(bs)
7373
}
7474

7575
func (p *simpleSharedBufferPool) poolIdx(size int) int {
@@ -119,23 +119,22 @@ type bufferPool struct {
119119
}
120120

121121
func (p *bufferPool) Get(size int) []byte {
122-
bs := p.Pool.Get().(*[]byte)
122+
bs := p.Pool.Get().([]byte)
123123

124-
if cap(*bs) < size {
124+
if cap(bs) < size {
125125
p.Pool.Put(bs)
126126

127127
return make([]byte, size)
128128
}
129129

130-
return (*bs)[:size]
130+
return (bs)[:size]
131131
}
132132

133133
func newBytesPool(size int) simpleSharedBufferChildPool {
134134
return &bufferPool{
135135
Pool: sync.Pool{
136136
New: func() interface{} {
137-
bs := make([]byte, size)
138-
return &bs
137+
return make([]byte, size)
139138
},
140139
},
141140
defaultSize: size,
@@ -150,5 +149,5 @@ func (nopBufferPool) Get(length int) []byte {
150149
return make([]byte, length)
151150
}
152151

153-
func (nopBufferPool) Put(*[]byte) {
152+
func (nopBufferPool) Put([]byte) {
154153
}

shared_buffer_pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (s) TestSharedBufferPool(t *testing.T) {
4242
t.Fatalf("Expected buffer of length %d, got %d", l, len(bs))
4343
}
4444

45-
p.Put(&bs)
45+
p.Put(bs)
4646
}
4747
}
4848
}

0 commit comments

Comments
 (0)