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

@@ -28,15 +28,16 @@ namespace OpenRA.Mods.Cnc.FileFormats
while (s.Peek() > -1) while (s.Peek() > -1)
{ {
var count = s.ReadInt32(); var count = s.ReadInt32();
var chars = new List<char>();
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
var chars = new List<char>();
byte c; byte c;
// Read filename // Read filename
while ((c = s.ReadUInt8()) != 0) while ((c = s.ReadUInt8()) != 0)
chars.Add((char)c); chars.Add((char)c);
entries.Add(new string(chars.ToArray())); entries.Add(new string(chars.ToArray()));
chars.Clear();
// Skip comment // Skip comment
while ((c = s.ReadUInt8()) != 0) { } while ((c = s.ReadUInt8()) != 0) { }

View File

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