MiniYaml becomes an immutable data structure.
This changeset is motivated by a simple concept - get rid of the MiniYaml.Clone and MiniYamlNode.Clone methods to avoid deep copying yaml trees during merging. MiniYaml becoming immutable allows the merge function to reuse existing yaml trees rather than cloning them, saving on memory and improving merge performance. On initial loading the YAML for all maps is processed, so this provides a small reduction in initial loading time. The rest of the changeset is dealing with the change in the exposed API surface. Some With* helper methods are introduced to allow creating new YAML from existing YAML. Areas of code that generated small amounts of YAML are able to transition directly to the immutable model without too much ceremony. Some use cases are far less ergonomic even with these helper methods and so a MiniYamlBuilder is introduced to retain mutable creation functionality. This allows those areas to continue to use the old mutable structures. The main users are the update rules and linting capabilities.
This commit is contained in:
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
|
||||
static readonly string[] AffectedTraits = new string[] { "GrantExternalConditionPower", "ChronoshiftPower" };
|
||||
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
|
||||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
|
||||
{
|
||||
foreach (var at in AffectedTraits)
|
||||
foreach (var trait in actorNode.ChildrenMatching(at))
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
yield break;
|
||||
}
|
||||
|
||||
void UpdatePower(MiniYamlNode power)
|
||||
void UpdatePower(MiniYamlNodeBuilder power)
|
||||
{
|
||||
var range = 1;
|
||||
var rangeNode = power.LastChildMatching("Range");
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
}
|
||||
|
||||
var size = 2 * range + 1;
|
||||
power.AddNode(new MiniYamlNode("Dimensions", size.ToString() + ", " + size.ToString()));
|
||||
power.AddNode(new MiniYamlNodeBuilder("Dimensions", size.ToString() + ", " + size.ToString()));
|
||||
|
||||
var footprint = string.Empty;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
footprint += ' ';
|
||||
}
|
||||
|
||||
power.AddNode(new MiniYamlNode("Footprint", footprint));
|
||||
power.AddNode(new MiniYamlNodeBuilder("Footprint", footprint));
|
||||
}
|
||||
|
||||
readonly List<string> locations = new();
|
||||
|
||||
Reference in New Issue
Block a user