perf: only allocate cacheableList once

This commit is contained in:
Christopher Felegy
2019-05-17 19:20:55 -04:00
parent 358b9e7b7b
commit 76f82d687b
2 changed files with 4 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
@@ -9,6 +9,6 @@ namespace Discord.API.Gateway
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("ids")]
public IEnumerable<ulong> Ids { get; set; }
public ulong[] Ids { get; set; }
}
}

View File

@@ -1375,13 +1375,13 @@ namespace Discord.WebSocket
return;
}
var cacheableList = ImmutableArray<Cacheable<IMessage, ulong>>.Empty;
var cacheableList = new List<Cacheable<IMessage, ulong>>(data.Ids.Length);
foreach (ulong id in data.Ids)
{
var msg = SocketChannelHelper.RemoveMessage(channel, this, id);
bool isCached = msg != null;
var cacheable = new Cacheable<IMessage, ulong>(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false));
cacheableList = cacheableList.Add(cacheable);
cacheableList.Add(cacheable);
if (!ExclusiveBulkDelete ?? false) // this shouldn't happen, but we'll play it safe anyways
await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false);