Add various optimizations and cleanups (#1114)

* Change all Select(... as ...) to OfType

* Add changes according to 194a8aa427
This commit is contained in:
Still Hsu
2018-08-31 05:36:44 +08:00
committed by Christopher F
parent a2d8800115
commit 82cfdffc65
46 changed files with 131 additions and 135 deletions

View File

@@ -63,9 +63,9 @@ namespace Discord.WebSocket
public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds;
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels;
public IReadOnlyCollection<SocketDMChannel> DMChannels
=> State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray();
=> State.PrivateChannels.OfType<SocketDMChannel>().ToImmutableArray();
public IReadOnlyCollection<SocketGroupChannel> GroupChannels
=> State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray();
=> State.PrivateChannels.OfType<SocketGroupChannel>().ToImmutableArray();
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection();
/// <summary> Creates a new REST/WebSocket discord client. </summary>
@@ -207,7 +207,7 @@ namespace Discord.WebSocket
await heartbeatTask.ConfigureAwait(false);
_heartbeatTask = null;
while (_heartbeatTimes.TryDequeue(out long time)) { }
while (_heartbeatTimes.TryDequeue(out _)) { }
_lastMessageTime = 0;
await _gatewayLogger.DebugAsync("Waiting for guild downloader").ConfigureAwait(false);
@@ -218,7 +218,7 @@ namespace Discord.WebSocket
//Clear large guild queue
await _gatewayLogger.DebugAsync("Clearing large guild queue").ConfigureAwait(false);
while (_largeGuilds.TryDequeue(out ulong guildId)) { }
while (_largeGuilds.TryDequeue(out _)) { }
//Raise virtual GUILD_UNAVAILABLEs
await _gatewayLogger.DebugAsync("Raising virtual GuildUnavailables").ConfigureAwait(false);
@@ -351,7 +351,7 @@ namespace Discord.WebSocket
var gameModel = new GameModel();
// Discord only accepts rich presence over RPC, don't even bother building a payload
if (Activity is RichGame game)
if (Activity is RichGame)
throw new NotSupportedException("Outgoing Rich Presences are not supported");
if (Activity != null)
@@ -508,7 +508,7 @@ namespace Discord.WebSocket
{
type = "GUILD_AVAILABLE";
_lastGuildAvailableTime = Environment.TickCount;
await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_AVAILABLE)").ConfigureAwait(false);
await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_AVAILABLE)").ConfigureAwait(false);
var guild = State.GetGuild(data.Id);
if (guild != null)
@@ -533,7 +533,7 @@ namespace Discord.WebSocket
}
else
{
await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_CREATE)").ConfigureAwait(false);
await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_CREATE)").ConfigureAwait(false);
var guild = AddGuild(data, State);
if (guild != null)
@@ -614,7 +614,7 @@ namespace Discord.WebSocket
if (data.Unavailable == true)
{
type = "GUILD_UNAVAILABLE";
await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_UNAVAILABLE)").ConfigureAwait(false);
await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_UNAVAILABLE)").ConfigureAwait(false);
var guild = State.GetGuild(data.Id);
if (guild != null)
@@ -630,7 +630,7 @@ namespace Discord.WebSocket
}
else
{
await _gatewayLogger.DebugAsync($"Received Dispatch (GUILD_DELETE)").ConfigureAwait(false);
await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_DELETE)").ConfigureAwait(false);
var guild = RemoveGuild(data.Id);
if (guild != null)
@@ -1626,7 +1626,7 @@ namespace Discord.WebSocket
var guild = State.RemoveGuild(id);
if (guild != null)
{
foreach (var channel in guild.Channels)
foreach (var _ in guild.Channels)
State.RemoveChannel(id);
foreach (var user in guild.Users)
user.GlobalUser.RemoveRef(this);
@@ -1679,7 +1679,7 @@ namespace Discord.WebSocket
if (eventHandler.HasSubscribers)
{
if (HandlerTimeout.HasValue)
await TimeoutWrap(name, () => eventHandler.InvokeAsync()).ConfigureAwait(false);
await TimeoutWrap(name, eventHandler.InvokeAsync).ConfigureAwait(false);
else
await eventHandler.InvokeAsync().ConfigureAwait(false);
}