1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Removed unnecessary allocation

This commit is contained in:
lidgren
2014-08-12 20:44:39 +00:00
parent c2f8346ca3
commit 715746eed3
2 changed files with 5 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ namespace Lidgren.Network
int bitsLeft = msg.LengthBits; int bitsLeft = msg.LengthBits;
for (int i = 0; i < numChunks; i++) for (int i = 0; i < numChunks; i++)
{ {
NetOutgoingMessage chunk = CreateMessage(mtu); NetOutgoingMessage chunk = CreateMessage(0);
chunk.m_bitLength = (bitsLeft > bitsPerChunk ? bitsPerChunk : bitsLeft); chunk.m_bitLength = (bitsLeft > bitsPerChunk ? bitsPerChunk : bitsLeft);
chunk.m_data = msg.m_data; chunk.m_data = msg.m_data;

View File

@@ -84,10 +84,8 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public NetOutgoingMessage CreateMessage(string content) public NetOutgoingMessage CreateMessage(string content)
{ {
byte[] bytes = Encoding.UTF8.GetBytes(content); var om = CreateMessage(2 + content.Length); // fair guess
NetOutgoingMessage om = CreateMessage(2 + bytes.Length); om.Write(content);
om.WriteVariableUInt32((uint)bytes.Length);
om.Write(bytes);
return om; return om;
} }
@@ -101,8 +99,8 @@ namespace Lidgren.Network
if (m_outgoingMessagesPool == null || !m_outgoingMessagesPool.TryDequeue(out retval)) if (m_outgoingMessagesPool == null || !m_outgoingMessagesPool.TryDequeue(out retval))
retval = new NetOutgoingMessage(); retval = new NetOutgoingMessage();
byte[] storage = GetStorage(initialCapacity); if (initialCapacity > 0)
retval.m_data = storage; retval.m_data = GetStorage(initialCapacity);
return retval; return retval;
} }