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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user