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 {
40
40
return & buf
41
41
}
42
42
43
+ // if the size is < than the minPoolSizePower we return an array from the first pool
43
44
if index < 0 {
44
45
index = 0
45
46
}
@@ -52,13 +53,9 @@ func (sp *byteSlicePools) getSlice(size int) *[]byte {
52
53
func (sp * byteSlicePools ) reuseSlice (s * []byte ) {
53
54
index := int (math .Floor (math .Log2 (float64 (cap (* s ))))) - minPoolSizePower
54
55
55
- if index >= len (sp .pools ) {
56
+ if index >= len (sp .pools ) || index < 0 {
56
57
return
57
58
}
58
59
59
- if index < 0 {
60
- index = 0
61
- }
62
-
63
60
sp .pools [index ].Put (s )
64
61
}
Original file line number Diff line number Diff line change @@ -19,3 +19,12 @@ func TestFuzzyByteSlicePools(t *testing.T) {
19
19
sut .reuseSlice (s )
20
20
}
21
21
}
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) {
98
98
bytePool .reuseSlice (req .data )
99
99
req .data = nil
100
100
}
101
-
101
+ req .Source = 0
102
+ req .Metadata = nil
103
+ req .Timeseries = nil
102
104
writeRequestPool .Put (req )
103
105
}
104
106
You can’t perform that action at this time.
0 commit comments