p2p: use package slices to sort in PeersInfo (#29957)
This commit is contained in:
parent
349fcdd22d
commit
8bda642963
|
@ -19,6 +19,7 @@ package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"cmp"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -1140,12 +1141,9 @@ func (srv *Server) PeersInfo() []*PeerInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sort the result array alphabetically by node identifier
|
// Sort the result array alphabetically by node identifier
|
||||||
for i := 0; i < len(infos); i++ {
|
slices.SortFunc(infos, func(a, b *PeerInfo) int {
|
||||||
for j := i + 1; j < len(infos); j++ {
|
return cmp.Compare(a.ID, b.ID)
|
||||||
if infos[i].ID > infos[j].ID {
|
})
|
||||||
infos[i], infos[j] = infos[j], infos[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return infos
|
return infos
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue