mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-08 07:58:40 +00:00
core/state: change StateCounts.Add to value receiver
The struct is 80 bytes (10 ints) — value semantics matches the type's "snapshot, safe to pass by value" thesis stated in its doc comment, and removes three unnecessary &-takings at call sites. No behavior change.
This commit is contained in:
parent
cdfad0d343
commit
1afcea992c
4 changed files with 8 additions and 7 deletions
|
|
@ -657,7 +657,7 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
|
|||
// (account/code/storage write counters via stateTransition.WriteCounts).
|
||||
stats.StateCounts = res.Counts
|
||||
balWrites := stateTransition.WriteCounts()
|
||||
stats.StateCounts.Add(&balWrites)
|
||||
stats.StateCounts.Add(balWrites)
|
||||
|
||||
// Time durations under parallel execution use wall-clock semantics.
|
||||
// Per-tx duration sums (CPU-time) are intentionally not plumbed: they
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func TestStateCountsAdd(t *testing.T) {
|
|||
CodeUpdated: 900,
|
||||
CodeUpdateBytes: 1000,
|
||||
}
|
||||
a.Add(&b)
|
||||
a.Add(b)
|
||||
want := state.StateCounts{
|
||||
AccountLoaded: 101,
|
||||
AccountUpdated: 202,
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, tExecStar
|
|||
// would otherwise be discarded; this captures system-contract reads and
|
||||
// the engine.Finalize state mutations.
|
||||
postTxCounts := postTxState.SnapshotCounts()
|
||||
aggCounts.Add(&postTxCounts)
|
||||
aggCounts.Add(postTxCounts)
|
||||
|
||||
// Fold post-tx statedb reads into the aggregate (system contracts,
|
||||
// withdrawal queue, consolidation queue).
|
||||
|
|
@ -267,7 +267,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxReads ba
|
|||
cumulativeStateGas += res.txState
|
||||
results = append(results, res)
|
||||
accesses.Merge(res.stateReads)
|
||||
aggCounts.Add(&res.counts)
|
||||
aggCounts.Add(res.counts)
|
||||
aggAccountReads += res.accountReads
|
||||
aggStorageReads += res.storageReads
|
||||
aggCodeReads += res.codeReads
|
||||
|
|
|
|||
|
|
@ -43,9 +43,10 @@ type StateCounts struct {
|
|||
}
|
||||
|
||||
// Add merges other into c. Plain integer addition — no atomics here, since
|
||||
// StateCounts is the snapshot type. Callers must ensure other is no longer
|
||||
// being mutated when Add is invoked.
|
||||
func (c *StateCounts) Add(other *StateCounts) {
|
||||
// StateCounts is the snapshot type. The receiver is the only mutated party;
|
||||
// other is taken by value (the struct is small and value semantics matches
|
||||
// the snapshot thesis stated above).
|
||||
func (c *StateCounts) Add(other StateCounts) {
|
||||
c.AccountLoaded += other.AccountLoaded
|
||||
c.AccountUpdated += other.AccountUpdated
|
||||
c.AccountDeleted += other.AccountDeleted
|
||||
|
|
|
|||
Loading…
Reference in a new issue