File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ func (sp *byteSlicePools) getSlice(size int) *[]byte {
4040 return & buf
4141 }
4242
43+ // if the size is < than the minPoolSizePower we return an array from the first pool
4344 if index < 0 {
4445 index = 0
4546 }
@@ -52,13 +53,9 @@ func (sp *byteSlicePools) getSlice(size int) *[]byte {
5253func (sp * byteSlicePools ) reuseSlice (s * []byte ) {
5354 index := int (math .Floor (math .Log2 (float64 (cap (* s ))))) - minPoolSizePower
5455
55- if index >= len (sp .pools ) {
56+ if index >= len (sp .pools ) || index < 0 {
5657 return
5758 }
5859
59- if index < 0 {
60- index = 0
61- }
62-
6360 sp .pools [index ].Put (s )
6461}
Original file line number Diff line number Diff line change @@ -19,3 +19,12 @@ func TestFuzzyByteSlicePools(t *testing.T) {
1919 sut .reuseSlice (s )
2020 }
2121}
22+
23+ func TestReturnSliceSmallerThanMin (t * testing.T ) {
24+ sut := newSlicePool (20 )
25+ size := 3
26+ buff := make ([]byte , 0 , size )
27+ sut .reuseSlice (& buff )
28+ buff2 := sut .getSlice (size * 2 )
29+ assert .Equal (t , len (* buff2 ), size * 2 )
30+ }
Original file line number Diff line number Diff line change @@ -98,7 +98,9 @@ func ReuseWriteRequest(req *PreallocWriteRequest) {
9898 bytePool .reuseSlice (req .data )
9999 req .data = nil
100100 }
101-
101+ req .Source = 0
102+ req .Metadata = nil
103+ req .Timeseries = nil
102104 writeRequestPool .Put (req )
103105}
104106
You can’t perform that action at this time.
0 commit comments