mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32: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"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -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++ {
|
sort.Slice(infos, func(i, j int) bool {
|
||||||
for j := i + 1; j < len(infos); j++ {
|
return infos[i].ID < infos[j].ID
|
||||||
if infos[i].ID > infos[j].ID {
|
})
|
||||||
infos[i], infos[j] = infos[j], infos[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return infos
|
return infos
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue