mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-18 08:20:53 +00:00
Using map[string]struct{} as a set to store unique values
This commit is contained in:
parent
e0e35ccb15
commit
95725c121e
1 changed files with 8 additions and 6 deletions
|
@ -17,7 +17,7 @@ func dnsReadConfig() (servers []string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
seenIPs := make(map[string]bool)
|
||||
uniqueIPs := make(map[string]struct{})
|
||||
|
||||
for _, aa := range aas {
|
||||
for dns := aa.FirstDnsServerAddress; dns != nil; dns = dns.Next {
|
||||
|
@ -44,13 +44,15 @@ func dnsReadConfig() (servers []string, err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
ipStr := ip.String()
|
||||
if !seenIPs[ipStr] {
|
||||
seenIPs[ipStr] = true
|
||||
servers = append(servers, ipStr)
|
||||
}
|
||||
uniqueIPs[ip.String()] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
servers = make([]string, 0, len(uniqueIPs))
|
||||
for ip := range uniqueIPs {
|
||||
servers = append(servers, ip)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue