replacing bubble sort algorithm in PeersInfo method, with the sort.Slice of the standard library

This commit is contained in:
Gealber 2024-06-08 15:00:57 +02:00
parent 1098d148a5
commit b6e88e78b5

View file

@ -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
} }