erigon-pulse/common/pool/pool_stack.go
2020-06-05 17:45:56 +03:00

39 lines
510 B
Go

package pool
import (
"sync"
"github.com/ledgerwatch/turbo-geth/core/vm/stack"
)
var StackPool = NewStack()
type Stack struct {
*sync.Pool
}
const maxCap = 1024 * 2
func NewStack() *Stack {
return &Stack{
&sync.Pool{
New: func() interface{} {
return stack.New(maxCap)
},
},
}
}
func (p *Stack) Get() *stack.Stack {
return p.Pool.Get().(*stack.Stack)
}
func (p *Stack) Put(s *stack.Stack) {
if s == nil || s.Cap() == 0 || s.Cap() > maxCap {
return
}
s.Reset()
p.Pool.Put(s)
}