mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
replacing bubble sort algorithm in PeersInfo method, with the sort.Slice of the standard library
This commit is contained in:
parent
1098d148a5
commit
b6e88e78b5
1 changed files with 5 additions and 7 deletions
|
|
@ -26,6 +26,7 @@ import (
|
|||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"sort"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
|
@ -1140,12 +1141,9 @@ func (srv *Server) PeersInfo() []*PeerInfo {
|
|||
}
|
||||
}
|
||||
// Sort the result array alphabetically by node identifier
|
||||
for i := 0; i < len(infos); i++ {
|
||||
for j := i + 1; j < len(infos); j++ {
|
||||
if infos[i].ID > infos[j].ID {
|
||||
infos[i], infos[j] = infos[j], infos[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Slice(infos, func(i, j int) bool {
|
||||
return infos[i].ID < infos[j].ID
|
||||
})
|
||||
|
||||
return infos
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue