mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
core/rawdb: reduce allocs in block key functions
This commit is contained in:
parent
a9eaf2ffd8
commit
b658ce7548
1 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue