From 07e7e8f2e04199cdae1477d5160320000f67ce4f Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 16 Dec 2025 11:07:37 +0530 Subject: [PATCH] core/rawdb: refactor headerKey to prealloc + copy --- core/rawdb/schema.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index d9140c5fd6..a1e07a78a2 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -191,7 +191,15 @@ 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) + off += copy(out[off:], encodeBlockNumber(number)) + copy(out[off:], hash.Bytes()) + + return out } // headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix