mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
core/rawdb: refactor headerKey to prealloc + copy
This commit is contained in:
parent
e20b05ec7f
commit
07e7e8f2e0
1 changed files with 9 additions and 1 deletions
|
|
@ -191,7 +191,15 @@ func headerKeyPrefix(number uint64) []byte {
|
||||||
|
|
||||||
// headerKey = headerPrefix + num (uint64 big endian) + hash
|
// headerKey = headerPrefix + num (uint64 big endian) + hash
|
||||||
func headerKey(number uint64, hash common.Hash) []byte {
|
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
|
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue