|
|
|
|
|
by voidlogic
2372 days ago
|
|
This code should just call sha1.New(). If for some reason these allocations are a performance issue it is very simple to fix that will a little pooling: package main
import (
"crypto/sha1"
"hash"
"sync"
)
func main() {
hasher := getHasher()
defer poolHasher(hasher)
}
var hasherPool sync.Pool = sync.Pool{
New: func() interface{} {
return sha1.New()
},
}
func getHasher() hash.Hash {
return hasherPool.Get().(hash.Hash)
}
func poolHasher(hasher hash.Hash) {
hasher.Reset()
hasherPool.Put(hasher)
}
|
|