使用List取代HashSet

This commit is contained in:
陈国伟 2021-06-16 17:18:21 +08:00
parent 9b7c8fb5f2
commit c7c69004bf
2 changed files with 10 additions and 5 deletions

View File

@ -7,13 +7,18 @@ namespace FastGithub.Scanner
sealed class GithubContextCollection sealed class GithubContextCollection
{ {
private readonly object syncRoot = new(); private readonly object syncRoot = new();
private readonly HashSet<GithubContext> contextHashSet = new(); private readonly List<GithubContext> contextList = new();
public bool Add(GithubContext context) public bool Add(GithubContext context)
{ {
lock (this.syncRoot) lock (this.syncRoot)
{ {
return this.contextHashSet.Add(context); if (this.contextList.Contains(context))
{
return false;
}
this.contextList.Add(context);
return true;
} }
} }
@ -21,7 +26,7 @@ namespace FastGithub.Scanner
{ {
lock (this.syncRoot) lock (this.syncRoot)
{ {
return this.contextHashSet.ToArray(); return this.contextList.ToArray();
} }
} }
@ -34,7 +39,7 @@ namespace FastGithub.Scanner
{ {
lock (this.syncRoot) lock (this.syncRoot)
{ {
return this.contextHashSet return this.contextList
.Where(item => item.Available && item.Domain == domain) .Where(item => item.Available && item.Domain == domain)
.OrderByDescending(item => item.Statistics.GetSuccessRate()) .OrderByDescending(item => item.Statistics.GetSuccessRate())
.ThenBy(item => item.Statistics.GetAvgElapsed()) .ThenBy(item => item.Statistics.GetAvgElapsed())

View File

@ -5,7 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks> <TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<Version>1.0.2</Version> <Version>1.0.0-beta1</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'"> <PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">