Introduce pools to obfuscated2

This commit is contained in:
9seconds
2021-03-18 15:01:22 +03:00
parent 58335b3e59
commit 3a44bcb854
4 changed files with 51 additions and 56 deletions
+20 -5
View File
@@ -6,11 +6,18 @@ import (
"sync"
)
var sha256HasherPool = sync.Pool{
New: func() interface{} {
return sha256.New()
},
}
var (
sha256HasherPool = sync.Pool{
New: func() interface{} {
return sha256.New()
},
}
handshakeFramePool = sync.Pool{
New: func() interface{} {
return &handshakeFrame{}
},
}
)
func acquireSha256Hasher() hash.Hash {
return sha256HasherPool.Get().(hash.Hash)
@@ -20,3 +27,11 @@ func releaseSha256Hasher(h hash.Hash) {
h.Reset()
sha256HasherPool.Put(h)
}
func acquireHandshakeFrame() *handshakeFrame {
return handshakeFramePool.Get().(*handshakeFrame)
}
func releaseHandshakeFrame(h *handshakeFrame) {
handshakeFramePool.Put(h)
}