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:
@@ -21,9 +21,9 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
|
||||
public override string Description => "Negative sequence length is no longer allowed, define individual frames in reverse instead.";
|
||||
|
||||
List<MiniYamlNode> resolvedImagesNodes;
|
||||
List<MiniYamlNodeBuilder> resolvedImagesNodes;
|
||||
|
||||
public IEnumerable<string> BeforeUpdateSequences(ModData modData, List<MiniYamlNode> resolvedImagesNodes)
|
||||
public IEnumerable<string> BeforeUpdateSequences(ModData modData, List<MiniYamlNodeBuilder> resolvedImagesNodes)
|
||||
{
|
||||
this.resolvedImagesNodes = resolvedImagesNodes;
|
||||
yield break;
|
||||
@@ -31,12 +31,12 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
|
||||
|
||||
readonly Queue<Action> actionQueue = new();
|
||||
|
||||
static MiniYamlNode GetNode(string key, MiniYamlNode node, MiniYamlNode defaultNode)
|
||||
static MiniYamlNodeBuilder GetNode(string key, MiniYamlNodeBuilder node, MiniYamlNodeBuilder defaultNode)
|
||||
{
|
||||
return node.LastChildMatching(key, includeRemovals: false) ?? defaultNode?.LastChildMatching(key, includeRemovals: false);
|
||||
}
|
||||
|
||||
public override IEnumerable<string> UpdateSequenceNode(ModData modData, MiniYamlNode sequenceNode)
|
||||
public override IEnumerable<string> UpdateSequenceNode(ModData modData, MiniYamlNodeBuilder sequenceNode)
|
||||
{
|
||||
var defaultNode = sequenceNode.LastChildMatching("Defaults");
|
||||
var defaultLengthNode = defaultNode == null ? null : GetNode("Length", defaultNode, null);
|
||||
|
||||
Reference in New Issue
Block a user