FILE / ScuroNeko/mtg

mtglib/internal/obfuscated2/pools.go

Исходный файл и его история в репозитории.
FILE bdabb0e59a90b15e1f9440e974b3a83d57eccd51
Files
mtg/mtglib/internal/obfuscated2/pools.go
T
2022-08-08 15:54:38 +03:00

40 lines
659 B
Go

package obfuscated2
import (
"bytes"
"crypto/sha256"
"hash"
"sync"
)
var (
sha256HasherPool = sync.Pool{
New: func() interface{} {
return sha256.New()
},
}
bytesBufferPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
func acquireSha256Hasher() hash.Hash {
return sha256HasherPool.Get().(hash.Hash) //nolint: forcetypeassert
}
func releaseSha256Hasher(h hash.Hash) {
h.Reset()
sha256HasherPool.Put(h)
}
func acquireBytesBuffer() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer) //nolint: forcetypeassert
}
func releaseBytesBuffer(buf *bytes.Buffer) {
buf.Reset()
bytesBufferPool.Put(buf)
}