mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
core/rawdb: refactor headerHashKey to prealloc + copy
This commit is contained in:
parent
07e7e8f2e0
commit
9ee65abaaa
1 changed files with 9 additions and 1 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue