Reuse buffers when loading Xcc databases.

We can reuse the list as a buffer when reading strings to avoid throwaway allocations, which will reduce GC pressure during loading.
This commit is contained in:
RoosterDragon
2017-11-17 19:39:15 +00:00
committed by Pavel Penev
parent c48ddbdfa5
commit 6a97502e09
2 changed files with 4 additions and 2 deletions

View File

@@ -26,14 +26,15 @@ namespace OpenRA.Mods.Cnc.FileFormats
var reader = new BinaryReader(s);
var count = reader.ReadInt32();
Entries = new string[count];
var chars = new List<char>();
for (var i = 0; i < count; i++)
{
var chars = new List<char>();
char c;
while ((c = reader.ReadChar()) != 0)
chars.Add(c);
Entries[i] = new string(chars.ToArray());
chars.Clear();
}
}