trie/bintrie: use sha256.Sum256 with stack buffer in InternalNode.Hash

Replace the sync.Pool-based sha256 hashing with a single sha256.Sum256
call using a stack-allocated [64]byte buffer. This eliminates pool
Get/Put overhead, two interface-dispatched Write() calls, the Sum(nil)
heap allocation, and the BytesToHash conversion.
This commit is contained in:
CPerezz 2026-03-16 23:56:04 +01:00
parent 98b13f342f
commit dfc7439cf5
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -17,6 +17,7 @@
package bintrie
import (
"crypto/sha256"
"errors"
"fmt"
@ -124,19 +125,14 @@ func (bt *InternalNode) Hash() common.Hash {
return bt.hash
}
h := newSha256()
defer returnSha256(h)
var buf [64]byte
if bt.left != nil {
h.Write(bt.left.Hash().Bytes())
} else {
h.Write(zero[:])
copy(buf[:32], bt.left.Hash().Bytes())
}
if bt.right != nil {
h.Write(bt.right.Hash().Bytes())
} else {
h.Write(zero[:])
copy(buf[32:], bt.right.Hash().Bytes())
}
bt.hash = common.BytesToHash(h.Sum(nil))
bt.hash = sha256.Sum256(buf[:])
bt.mustRecompute = false
return bt.hash
}