Optimize updating of server list

We can compare new endpoints firstly, to save Save() call if they're equal values-wise.
This commit is contained in:
JustArchi
2016-08-19 04:10:49 +02:00
parent 134aa62952
commit 214746bca2

View File

@@ -40,17 +40,19 @@ namespace ArchiSteamFarm {
public Task<IEnumerable<IPEndPoint>> FetchServerListAsync() => Task.FromResult<IEnumerable<IPEndPoint>>(Servers);
public Task UpdateServerListAsync(IEnumerable<IPEndPoint> endpoints) {
if (endpoints == null) {
Logging.LogNullError(nameof(endpoints));
public Task UpdateServerListAsync(IEnumerable<IPEndPoint> endPoints) {
if (endPoints == null) {
Logging.LogNullError(nameof(endPoints));
return Task.Delay(0);
}
Servers.Clear();
foreach (IPEndPoint endpoint in endpoints) {
Servers.Add(endpoint);
HashSet<IPEndPoint> newEndPoints = new HashSet<IPEndPoint>(endPoints);
if (Servers.SetEquals(newEndPoints)) {
return Task.Delay(0);
}
Servers = newEndPoints;
ServerListUpdated(this, EventArgs.Empty);
return Task.Delay(0);