Avoid some allocations during loading.

- In FieldLoader, cache boxed bools and some boxed ints.
- In FieldLoader, presize collections when parsing a List, HashSet or Dictionary.
- In FieldLoader, don't allocate a list of missing items until required.
- In FieldLoader, when a string value is passed, avoid wrapping this in a MiniYaml object by allowing both strings and yaml to be passed in the GetValue overload that does the real work.
- In Animation, avoid allocating no-op actions.
- In VxlReader, use EnsureCapcity to better size the Dictionary.
- In VxlReader change VxlElement to a struct.
- In Locomotor, presize TerrainSpeeds dictionary.
This commit is contained in:
RoosterDragon
2023-07-02 16:35:51 +01:00
committed by abcdefg30
parent be04d232c0
commit 58e8b123db
5 changed files with 55 additions and 29 deletions

View File

@@ -84,8 +84,9 @@ namespace OpenRA.Mods.Common.Traits
protected static object LoadSpeeds(MiniYaml y)
{
var ret = new Dictionary<string, TerrainInfo>();
foreach (var t in y.ToDictionary()["TerrainSpeeds"].Nodes)
var speeds = y.ToDictionary()["TerrainSpeeds"].Nodes;
var ret = new Dictionary<string, TerrainInfo>(speeds.Count);
foreach (var t in speeds)
{
var speed = FieldLoader.GetValue<int>("speed", t.Value.Value);
if (speed > 0)
@@ -98,6 +99,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
ret.TrimExcess();
return ret;
}