mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
use generic atomic types in block caches
This commit is contained in:
parent
b2d78be1b3
commit
a38de14ab6
1 changed files with 8 additions and 8 deletions
|
|
@ -197,8 +197,8 @@ type Block struct {
|
||||||
withdrawals Withdrawals
|
withdrawals Withdrawals
|
||||||
|
|
||||||
// caches
|
// caches
|
||||||
hash atomic.Value
|
hash atomic.Pointer[common.Hash]
|
||||||
size atomic.Value
|
size atomic.Uint64
|
||||||
|
|
||||||
// These fields are used by package eth to track
|
// These fields are used by package eth to track
|
||||||
// inter-peer block relay.
|
// inter-peer block relay.
|
||||||
|
|
@ -406,8 +406,8 @@ func (b *Block) BlobGasUsed() *uint64 {
|
||||||
// Size returns the true RLP encoded storage size of the block, either by encoding
|
// Size returns the true RLP encoded storage size of the block, either by encoding
|
||||||
// and returning it, or returning a previously cached value.
|
// and returning it, or returning a previously cached value.
|
||||||
func (b *Block) Size() uint64 {
|
func (b *Block) Size() uint64 {
|
||||||
if size := b.size.Load(); size != nil {
|
if size := b.size.Load(); size > 0 {
|
||||||
return size.(uint64)
|
return size
|
||||||
}
|
}
|
||||||
c := writeCounter(0)
|
c := writeCounter(0)
|
||||||
rlp.Encode(&c, b)
|
rlp.Encode(&c, b)
|
||||||
|
|
@ -486,11 +486,11 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
|
||||||
// The hash is computed on the first call and cached thereafter.
|
// The hash is computed on the first call and cached thereafter.
|
||||||
func (b *Block) Hash() common.Hash {
|
func (b *Block) Hash() common.Hash {
|
||||||
if hash := b.hash.Load(); hash != nil {
|
if hash := b.hash.Load(); hash != nil {
|
||||||
return hash.(common.Hash)
|
return *hash
|
||||||
}
|
}
|
||||||
v := b.header.Hash()
|
h := b.header.Hash()
|
||||||
b.hash.Store(v)
|
b.hash.Store(&h)
|
||||||
return v
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
type Blocks []*Block
|
type Blocks []*Block
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue