From 95725c121e23fa76c83d3bd93c0c858137c2be7c Mon Sep 17 00:00:00 2001 From: ForestL <45709305+ForestL18@users.noreply.github.com> Date: Sun, 18 Aug 2024 12:55:00 +0800 Subject: [PATCH] Using map[string]struct{} as a set to store unique values --- dns/system_windows.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dns/system_windows.go b/dns/system_windows.go index c87a37b1..28be405d 100644 --- a/dns/system_windows.go +++ b/dns/system_windows.go @@ -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 }