From 8a14428af33253d5b9ce84a625f75a7a85ba52b4 Mon Sep 17 00:00:00 2001 From: maskpp Date: Wed, 21 May 2025 20:49:47 +0800 Subject: [PATCH] revert the usage of hashBuf --- crypto/crypto.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index ff02cedbab..6af96f74cc 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -74,17 +74,9 @@ func NewKeccakState() KeccakState { return sha3.NewLegacyKeccak256().(KeccakState) } -type keccakState struct { - KeccakState - hashBuf common.Hash -} - var hasherPool = sync.Pool{ New: func() any { - return &keccakState{ - hashBuf: common.Hash{}, - KeccakState: sha3.NewLegacyKeccak256().(KeccakState), - } + return sha3.NewLegacyKeccak256().(KeccakState) }, } @@ -110,26 +102,26 @@ func Keccak256RLP(x interface{}) []byte { // Keccak256Hash calculates and returns the Keccak256 hash of the input data, // converting it to an internal Hash data structure. -func Keccak256Hash(data ...[]byte) common.Hash { - d := hasherPool.Get().(*keccakState) +func Keccak256Hash(data ...[]byte) (h common.Hash) { + d := hasherPool.Get().(KeccakState) d.Reset() for _, b := range data { d.Write(b) } - d.Read(d.hashBuf[:]) + d.Read(h[:]) hasherPool.Put(d) - return d.hashBuf + return h } // Keccak256RLPHash calculates and returns the Keccak256 hash of the input interface, // converting it to an internal Hash data structure. -func Keccak256RLPHash(x interface{}) common.Hash { - d := hasherPool.Get().(*keccakState) +func Keccak256RLPHash(x interface{}) (h common.Hash) { + d := hasherPool.Get().(KeccakState) d.Reset() rlp.Encode(d, x) - d.Read(d.hashBuf[:]) + d.Read(h[:]) hasherPool.Put(d) - return d.hashBuf + return h } // Keccak512 calculates and returns the Keccak512 hash of the input data.