mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-05 14:17: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"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -139,17 +140,11 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serversInfo.Lock()
|
serversInfo.Lock()
|
||||||
|
sort.SliceStable(serversInfo.inner, func(i, j int) bool {
|
||||||
|
return serversInfo.inner[i].initialRtt < serversInfo.inner[j].initialRtt
|
||||||
|
})
|
||||||
inner := serversInfo.inner
|
inner := serversInfo.inner
|
||||||
innerLen := len(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 {
|
if innerLen > 1 {
|
||||||
dlog.Notice("Sorted latencies:")
|
dlog.Notice("Sorted latencies:")
|
||||||
for i := 0; i < innerLen; i++ {
|
for i := 0; i < innerLen; i++ {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue