aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-04-14 18:20:29 -0500
committerJP Dillingham <jp@dillingham.me>2024-04-14 18:20:29 -0500
commit0ddd0626002c9ff15deffe91b78d3d5eae51d5ee (patch)
tree0cd8ec84d9f2662138a5ad3b3c8dcef3b3e6e11b
parent40443e3c576418f98ddbe0f616be55359cb74dcb (diff)
downloadslskd-0ddd0626002c9ff15deffe91b78d3d5eae51d5ee.tar.gz
sort values
-rw-r--r--src/slskd/Core/Blacklist.cs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/slskd/Core/Blacklist.cs b/src/slskd/Core/Blacklist.cs
index 907fd9ba..d7a680aa 100644
--- a/src/slskd/Core/Blacklist.cs
+++ b/src/slskd/Core/Blacklist.cs
@@ -21,6 +21,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net;
using System.Threading.Tasks;
using NetTools;
@@ -178,15 +179,14 @@ public class Blacklist
}
}
- // copy working dictionary to a temporary cache, converting List<> to array to increase access speed
+ // copy working dictionary to a temporary cache to:
+ // * convert List<> to array to increase access speed
+ // * sort arrays by first IP to enable binary search
var tempCache = new ConcurrentDictionary<int, (uint First, uint Last)[]>();
foreach (var key in dict.Keys)
{
- tempCache.AddOrUpdate(
- key,
- addValueFactory: (_) => dict[key].ToArray(),
- updateValueFactory: (_, _) => dict[key].ToArray());
+ tempCache[key] = dict[key].OrderBy(x => x.First).ToArray();
}
// swap the temporary cache for the "real" cache, enabling a bumpless update