core/state: minor optimization in state onleaf allocation

This commit is contained in:
Martin Holst Swende 2019-12-26 11:15:13 +01:00
parent 4670907ebe
commit ca1e6b3fb4
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -750,8 +750,10 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
if metrics.EnabledExpensive {
defer func(start time.Time) { s.AccountCommits += time.Since(start) }(time.Now())
}
return s.trie.Commit(func(leaf []byte, parent common.Hash) error {
// The onleaf func is called _serially_, so we can reuse the same account
// for unmarshalling every time.
var account Account
return s.trie.Commit(func(leaf []byte, parent common.Hash) error {
if err := rlp.DecodeBytes(leaf, &account); err != nil {
return nil
}