Skip to content

Commit

Permalink
core/types: remove use of package unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Gus authored and fjl committed Jan 29, 2019
1 parent 21acf0b commit 4eee99a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"encoding/binary"
"io"
"math/big"
"reflect"
"sort"
"sync/atomic"
"time"
"unsafe"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -102,10 +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 {
return common.StorageSize(unsafe.Sizeof(*h)) + 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) {
Expand Down

0 comments on commit 4eee99a

Please sign in to comment.