mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
triedb: use sync pool
This commit is contained in:
parent
b3131f00a3
commit
695545b49b
1 changed files with 8 additions and 2 deletions
|
|
@ -25,6 +25,12 @@ import (
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hashSlicePool = sync.Pool{
|
||||||
|
New: func() interface{} {
|
||||||
|
return make([]common.Hash, 0, 16)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// storageKey returns a key for uniquely identifying the storage slot.
|
// storageKey returns a key for uniquely identifying the storage slot.
|
||||||
func storageKey(accountHash common.Hash, slotHash common.Hash) [64]byte {
|
func storageKey(accountHash common.Hash, slotHash common.Hash) [64]byte {
|
||||||
var key [64]byte
|
var key [64]byte
|
||||||
|
|
@ -182,7 +188,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
|
||||||
for accountHash := range diff.states.accountData {
|
for accountHash := range diff.states.accountData {
|
||||||
list, exists := l.accounts[accountHash]
|
list, exists := l.accounts[accountHash]
|
||||||
if !exists {
|
if !exists {
|
||||||
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool
|
list = hashSlicePool.Get().([]common.Hash)
|
||||||
}
|
}
|
||||||
list = append(list, state)
|
list = append(list, state)
|
||||||
l.accounts[accountHash] = list
|
l.accounts[accountHash] = list
|
||||||
|
|
@ -197,7 +203,7 @@ func (l *lookup) addLayer(diff *diffLayer) {
|
||||||
key := storageKey(accountHash, slotHash)
|
key := storageKey(accountHash, slotHash)
|
||||||
list, exists := l.storages[key]
|
list, exists := l.storages[key]
|
||||||
if !exists {
|
if !exists {
|
||||||
list = make([]common.Hash, 0, 16) // TODO(rjl493456442) use sync pool
|
list = hashSlicePool.Get().([]common.Hash)
|
||||||
}
|
}
|
||||||
list = append(list, state)
|
list = append(list, state)
|
||||||
l.storages[key] = list
|
l.storages[key] = list
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue