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:
RoosterDragon
2023-05-06 10:39:15 +01:00
committed by Gustas
parent b6a5d19871
commit 949ba589c0
104 changed files with 722 additions and 393 deletions

View File

@@ -486,7 +486,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (string.IsNullOrEmpty(bl.Data))
continue;
var game = MiniYaml.FromString(bl.Data)[0].Value;
var game = new MiniYamlBuilder(MiniYaml.FromString(bl.Data)[0].Value);
var idNode = game.Nodes.FirstOrDefault(n => n.Key == "Id");
// Skip beacons created by this instance and replace Id by expected int value
@@ -499,9 +499,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (addressNode != null)
addressNode.Value.Value = bl.Address.ToString().Split(':')[0] + ":" + addressNode.Value.Value.Split(':')[1];
game.Nodes.Add(new MiniYamlNode("Location", "Local Network"));
game.Nodes.Add(new MiniYamlNodeBuilder("Location", "Local Network"));
lanGames.Add(new GameServer(game));
lanGames.Add(new GameServer(game.Build()));
}
}
catch