From b658ce7548c12eb2f3cdf269da6b1f3e234b8b64 Mon Sep 17 00:00:00 2001 From: m6xwzzz Date: Sat, 13 Dec 2025 13:15:35 +0800 Subject: [PATCH] core/rawdb: reduce allocs in block key functions --- core/rawdb/schema.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index d9140c5fd6..de160fe1ff 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -191,7 +191,18 @@ func headerKeyPrefix(number uint64) []byte { // headerKey = headerPrefix + num (uint64 big endian) + hash func headerKey(number uint64, hash common.Hash) []byte { - return append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...) + totalLen := len(headerPrefix) + 8 + common.HashLength + out := make([]byte, totalLen) + + off := 0 + off += copy(out[off:], headerPrefix) + + var enc [8]byte + binary.BigEndian.PutUint64(enc[:], number) + off += copy(out[off:], enc[:]) + + copy(out[off:], hash.Bytes()) + return out } // headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix