Browse Source

perf(messages_list): preallocate slice capacity

ayn2op 4 months ago
parent
commit
252a42780f
1 changed files with 2 additions and 2 deletions
  1. 2 2
      cmd/messages_list.go

+ 2 - 2
cmd/messages_list.go

@@ -642,7 +642,7 @@ func (ml *messagesList) delete() {
 }
 
 func (ml *messagesList) requestGuildMembers(gID discord.GuildID, ms []discord.Message) {
-	var usersToFetch []discord.UserID
+	usersToFetch := make([]discord.UserID, 0, len(ms))
 	for _, m := range ms {
 		// Do not fetch member for a webhook message.
 		if m.WebhookID.IsValid() {
@@ -654,7 +654,7 @@ func (ml *messagesList) requestGuildMembers(gID discord.GuildID, ms []discord.Me
 		}
 	}
 
-	if usersToFetch != nil {
+	if len(usersToFetch) > 0 {
 		err := discordState.SendGateway(context.TODO(), &gateway.RequestGuildMembersCommand{
 			GuildIDs: []discord.GuildID{gID},
 			UserIDs:  slices.Compact(usersToFetch),