Packet packing micro optimisation.

This commit is contained in:
flash 2024-05-20 16:24:14 +00:00
parent 610f9ab142
commit a0e6fbbeea
2 changed files with 16 additions and 7 deletions

View file

@ -372,14 +372,20 @@ namespace SharpChat {
}
public void Send(SockChatS2CPacket packet) {
Connections.WithAuthed(conn => conn.Send(packet));
string data = packet.Pack();
Connections.WithAuthed(conn => conn.Send(data));
}
public void SendTo(UserInfo user, SockChatS2CPacket packet) {
Connections.WithUser(user, conn => conn.Send(packet));
string data = packet.Pack();
Connections.WithUser(user, conn => conn.Send(data));
}
public void SendTo(ChannelInfo channel, SockChatS2CPacket packet) {
SendTo(channel, packet.Pack());
}
public void SendTo(ChannelInfo channel, string packet) {
long[] userIds = ChannelsUsers.GetChannelUserIds(channel);
foreach(long userId in userIds)
Connections.WithUser(userId, conn => conn.Send(packet));
@ -387,8 +393,9 @@ namespace SharpChat {
public void SendToUserChannels(UserInfo user, SockChatS2CPacket packet) {
ChannelInfo[] chans = GetUserChannels(user);
string data = packet.Pack();
foreach(ChannelInfo chan in chans)
SendTo(chan, packet);
SendTo(chan, data);
}
public void ForceChannel(UserInfo user, ChannelInfo? chan = null) {

View file

@ -42,12 +42,14 @@ namespace SharpChat {
}
public void Send(SockChatS2CPacket packet) {
if(!Socket.IsAvailable)
return;
string data = packet.Pack();
if(!string.IsNullOrWhiteSpace(data))
Socket.Send(data).Wait();
Send(data);
}
public void Send(string packet) {
if(Socket.IsAvailable)
Socket.Send(packet).Wait();
}
public void BumpPing() {