forked from grafana/loki
/
pool.go
47 lines (38 loc) · 778 Bytes
/
pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package tsdb
import (
"sync"
"github.com/grafana/loki/pkg/storage/stores/tsdb/index"
)
var (
ChunkMetasPool = &index.ChunkMetasPool // re-exporting
SeriesPool PoolSeries
ChunkRefsPool PoolChunkRefs
)
type PoolSeries struct {
pool sync.Pool
}
func (p *PoolSeries) Get() []Series {
if xs := p.pool.Get(); xs != nil {
return xs.([]Series)
}
return make([]Series, 0, 1<<10)
}
func (p *PoolSeries) Put(xs []Series) {
xs = xs[:0]
//nolint:staticcheck
p.pool.Put(xs)
}
type PoolChunkRefs struct {
pool sync.Pool
}
func (p *PoolChunkRefs) Get() []ChunkRef {
if xs := p.pool.Get(); xs != nil {
return xs.([]ChunkRef)
}
return make([]ChunkRef, 0, 1<<10)
}
func (p *PoolChunkRefs) Put(xs []ChunkRef) {
xs = xs[:0]
//nolint:staticcheck
p.pool.Put(xs)
}