perf: only allocate cacheableList once
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user