go-sample-webpage/vendor/github.com/lestrrat-go/jwx/internal/pool/pool.go

41 lines
586 B
Go
Raw Normal View History

2021-11-04 01:14:51 +00:00
package pool
import (
"bytes"
"math/big"
"sync"
)
var bytesBufferPool = sync.Pool{
New: allocBytesBuffer,
}
func allocBytesBuffer() interface{} {
return &bytes.Buffer{}
}
func GetBytesBuffer() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer)
}
func ReleaseBytesBuffer(b *bytes.Buffer) {
b.Reset()
bytesBufferPool.Put(b)
}
var bigIntPool = sync.Pool{
New: allocBigInt,
}
func allocBigInt() interface{} {
return &big.Int{}
}
func GetBigInt() *big.Int {
return bigIntPool.Get().(*big.Int)
}
func ReleaseBigInt(i *big.Int) {
bigIntPool.Put(i.SetInt64(0))
}