trie: refactor to use slices.Concat

This commit is contained in:
cuiweixie 2025-08-12 12:14:26 +08:00
parent cbbf686ecc
commit 905b2bfd68

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"
@ -471,7 +472,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
} }
@ -566,13 +567,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) {