Skip to content

Commit

Permalink
perf: only allocate cacheableList once
Browse files Browse the repository at this point in the history
  • Loading branch information
foxbot committed May 17, 2019
1 parent 358b9e7 commit 76f82d6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;

Expand All @@ -9,6 +9,6 @@ internal class MessageDeleteBulkEvent
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("ids")]
public IEnumerable<ulong> Ids { get; set; }
public ulong[] Ids { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,13 +1375,13 @@ await _gatewayLogger.WarningAsync("A bulk delete event has been received, but th
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);
Expand Down

0 comments on commit 76f82d6

Please sign in to comment.