core/rawdb: refactor headerHashKey to prealloc + copy

This commit is contained in:
Sahil-4555 2025-12-16 11:09:17 +05:30
parent 07e7e8f2e0
commit 9ee65abaaa

View file

@ -204,7 +204,15 @@ func headerKey(number uint64, hash common.Hash) []byte {
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix // headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
func headerHashKey(number uint64) []byte { func headerHashKey(number uint64) []byte {
return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...) totalLen := len(headerPrefix) + 8 + len(headerHashSuffix)
out := make([]byte, totalLen)
off := 0
off += copy(out[off:], headerPrefix)
off += copy(out[off:], encodeBlockNumber(number))
copy(out[off:], headerHashSuffix)
return out
} }
// headerNumberKey = headerNumberPrefix + hash // headerNumberKey = headerNumberPrefix + hash