Presize MemoryStream when possible.

Also use GetBuffer when we know we have presized the stream to the exact required size to prevent a needless copy.
This commit is contained in:
RoosterDragon
2017-12-07 21:28:43 +00:00
committed by abcdefg30
parent 5d8c9a560a
commit ca01a1f186
7 changed files with 19 additions and 13 deletions

View File

@@ -38,14 +38,14 @@ namespace OpenRA.Network
public static byte[] SerializeSync(int sync)
{
var ms = new MemoryStream();
var ms = new MemoryStream(1 + 4);
using (var writer = new BinaryWriter(ms))
{
writer.Write((byte)0x65);
writer.Write(sync);
}
return ms.ToArray();
return ms.GetBuffer();
}
public static int2 ReadInt2(this BinaryReader r)