mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-05 06:07:36 +03:00
change: serversInfo: Use sort instead of own implementation
This commit is contained in:
parent
9b019574a0
commit
21d71ac9be
1 changed files with 4 additions and 9 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"math/rand"
|
||||
"net"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -139,17 +140,11 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
|
|||
}
|
||||
}
|
||||
serversInfo.Lock()
|
||||
sort.SliceStable(serversInfo.inner, func(i, j int) bool {
|
||||
return serversInfo.inner[i].initialRtt < serversInfo.inner[j].initialRtt
|
||||
})
|
||||
inner := serversInfo.inner
|
||||
innerLen := len(inner)
|
||||
for i := 0; i < innerLen; i++ {
|
||||
for j := i + 1; j < innerLen; j++ {
|
||||
if inner[j].initialRtt < inner[i].initialRtt {
|
||||
inner[j], inner[i] = inner[i], inner[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
serversInfo.inner = inner
|
||||
|
||||
if innerLen > 1 {
|
||||
dlog.Notice("Sorted latencies:")
|
||||
for i := 0; i < innerLen; i++ {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue