core/types: use reflect

This commit is contained in:
Felix Lange 2019-01-26 14:41:59 +01:00 committed by GitHub
parent 4b3fe05fe7
commit 4404f0818d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ package types
import (
"encoding/binary"
"reflect"
"io"
"math/big"
"sort"
@ -101,11 +102,12 @@ func (h *Header) Hash() common.Hash {
return rlpHash(h)
}
var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size())
// Size returns the approximate memory used by all internal contents. It is used
// to approximate and limit the memory consumption of various caches.
func (h *Header) Size() common.StorageSize {
size := binary.Size(h)
return common.StorageSize(size) + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+h.Time.BitLen())/8)
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+h.Time.BitLen())/8)
}
func rlpHash(x interface{}) (h common.Hash) {