core, trie: polish

This commit is contained in:
Gary Rong 2025-08-20 15:48:36 +08:00
parent 3b354570a7
commit ca8c82edce
3 changed files with 6 additions and 13 deletions

View file

@ -63,6 +63,5 @@ func (w *Witness) MakeHashDB() ethdb.Database {
rawdb.WriteLegacyTrieNode(memdb, common.BytesToHash(hash), blob) rawdb.WriteLegacyTrieNode(memdb, common.BytesToHash(hash), blob)
} }
return memdb return memdb
} }

View file

@ -46,8 +46,8 @@ func newDepthStats() *depthStats {
return &depthStats{minDepth: -1} return &depthStats{minDepth: -1}
} }
// Add records a new depth sample. // add records a new depth sample.
func (d *depthStats) Add(n int64) { func (d *depthStats) add(n int64) {
if n < 0 { if n < 0 {
return return
} }
@ -92,11 +92,11 @@ func NewWitnessStats() *WitnessStats {
func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash) { func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash) {
if owner == (common.Hash{}) { if owner == (common.Hash{}) {
for path := range maps.Keys(nodes) { for path := range maps.Keys(nodes) {
s.accountTrie.Add(int64(len(path))) s.accountTrie.add(int64(len(path)))
} }
} else { } else {
for path := range maps.Keys(nodes) { for path := range maps.Keys(nodes) {
s.storageTrie.Add(int64(len(path))) s.storageTrie.add(int64(len(path)))
} }
} }
} }

View file

@ -21,6 +21,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"slices"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -517,7 +518,7 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
// always creates a new slice) instead of append to // always creates a new slice) instead of append to
// avoid modifying n.Key since it might be shared with // avoid modifying n.Key since it might be shared with
// other nodes. // other nodes.
return true, &shortNode{concat(n.Key, child.Key...), child.Val, t.newFlag()}, nil return true, &shortNode{slices.Concat(n.Key, child.Key...), child.Val, t.newFlag()}, nil
default: default:
return true, &shortNode{n.Key, child, t.newFlag()}, nil return true, &shortNode{n.Key, child, t.newFlag()}, nil
} }
@ -612,13 +613,6 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
} }
} }
func concat(s1 []byte, s2 ...byte) []byte {
r := make([]byte, len(s1)+len(s2))
copy(r, s1)
copy(r[len(s1):], s2)
return r
}
// copyNode deep-copies the supplied node along with its children recursively. // copyNode deep-copies the supplied node along with its children recursively.
func copyNode(n node) node { func copyNode(n node) node {
switch n := (n).(type) { switch n := (n).(type) {