From f89d32597786c05df7609c525852251950085ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Wed, 29 Sep 2021 14:42:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=88=97=E8=A1=A8=E5=8F=96?= =?UTF-8?q?=E4=BB=A3HashSet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.DomainResolve/DnsClient.cs | 9 ++++++--- FastGithub.DomainResolve/IPAddressCollection.cs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/FastGithub.DomainResolve/DnsClient.cs b/FastGithub.DomainResolve/DnsClient.cs index fe3b175..e97867b 100644 --- a/FastGithub.DomainResolve/DnsClient.cs +++ b/FastGithub.DomainResolve/DnsClient.cs @@ -265,12 +265,15 @@ namespace FastGithub.DomainResolve return addresses; } - var hashSet = new HashSet { fastedAddress }; + var list = new List { fastedAddress }; foreach (var address in addresses) { - hashSet.Add(address); + if (address.Equals(fastedAddress) == false) + { + list.Add(address); + } } - return hashSet.ToArray(); + return list.ToArray(); } /// diff --git a/FastGithub.DomainResolve/IPAddressCollection.cs b/FastGithub.DomainResolve/IPAddressCollection.cs index 2fc1122..9659161 100644 --- a/FastGithub.DomainResolve/IPAddressCollection.cs +++ b/FastGithub.DomainResolve/IPAddressCollection.cs @@ -41,7 +41,10 @@ namespace FastGithub.DomainResolve /// public IPAddress[] ToArray() { - return this.ToItemArray().OrderBy(item => item.PingElapsed).Select(item => item.Address).ToArray(); + lock (this.syncRoot) + { + return this.hashSet.OrderBy(item => item.PingElapsed).Select(item => item.Address).ToArray(); + } } ///