p2p: use slices package for sorting (#27494)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Dan Laine
2023-06-19 07:48:12 +02:00
committed by GitHub
co-authored by Felix Lange
parent 46ec972c9c
commit 289c6c3b15
8 changed files with 26 additions and 34 deletions
+3 -3
View File
@@ -23,7 +23,6 @@ import (
"encoding/base64"
"fmt"
"io"
"sort"
"strings"
"github.com/ethereum/go-ethereum/crypto"
@@ -31,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"
)
// Tree is a merkle tree of node records.
@@ -214,8 +214,8 @@ func (t *Tree) build(entries []entry) entry {
}
func sortByID(nodes []*enode.Node) []*enode.Node {
sort.Slice(nodes, func(i, j int) bool {
return bytes.Compare(nodes[i].ID().Bytes(), nodes[j].ID().Bytes()) < 0
slices.SortFunc(nodes, func(a, b *enode.Node) bool {
return bytes.Compare(a.ID().Bytes(), b.ID().Bytes()) < 0
})
return nodes
}