-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool.go
60 lines (51 loc) · 989 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
48
49
50
51
52
53
54
55
56
57
58
59
60
package strparam
import "sync"
var MaxListParamsCap = 32
var MaxListTokensCap = 128
var (
listParamsPool = sync.Pool{
New: func() interface{} { return make([]Param, 0, MaxListParamsCap) },
}
listTokensPool = sync.Pool{
New: func() interface{} { return make([]Token, 0, MaxListTokensCap) },
}
)
func getListParams() (v []Param) {
ifc := listParamsPool.Get()
if ifc != nil {
v = ifc.([]Param)
}
return
}
func putListParams(v []Param) {
if cap(v) <= MaxListParamsCap {
v = v[:0]
listParamsPool.Put(v)
}
}
func getlistTokens() (v []Token) {
ifc := listTokensPool.Get()
if ifc != nil {
v = ifc.([]Token)
}
return
}
func putlistTokens(v []Token) {
if cap(v) <= MaxListTokensCap {
v = v[:0]
listTokensPool.Put(v)
}
}
func (s *Store) getlistTokens() (v []Token) {
ifc := s.tokensPool.Get()
if ifc != nil {
v = ifc.([]Token)
}
return
}
func (s *Store) putlistTokens(v []Token) {
if cap(v) <= MaxListTokensCap {
v = v[:0]
s.tokensPool.Put(v)
}
}