-
Notifications
You must be signed in to change notification settings - Fork 5
/
pool.go
50 lines (41 loc) · 934 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
package fastrlp
import (
"sync"
)
// DefaultParserPool is a default ParserPool
var DefaultParserPool ParserPool
// ParserPool may be used for pooling Parsers for similarly typed RLPs.
type ParserPool struct {
pool sync.Pool
}
// Get acquires a Parser from the pool.
func (pp *ParserPool) Get() *Parser {
v := pp.pool.Get()
if v == nil {
return &Parser{}
}
return v.(*Parser)
}
// Put releases the parser to the pool.
func (pp *ParserPool) Put(p *Parser) {
pp.pool.Put(p)
}
// DefaultArenaPool is a default ArenaPool
var DefaultArenaPool ArenaPool
// ArenaPool may be used for pooling Arenas for similarly typed RLPs.
type ArenaPool struct {
pool sync.Pool
}
// Get acquires an Arena from the pool.
func (ap *ArenaPool) Get() *Arena {
v := ap.pool.Get()
if v == nil {
return &Arena{}
}
return v.(*Arena)
}
// Put releases an Arena to the pool.
func (ap *ArenaPool) Put(a *Arena) {
a.Reset()
ap.pool.Put(a)
}