diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 84b93788ed..455ffe0548 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -99,7 +99,10 @@ namespace OpenRA public MiniYaml Clone() { - return new MiniYaml(Value, Nodes.Select(n => n.Clone()).ToList()); + var clonedNodes = new MiniYamlNodes(Nodes.Count); + foreach (var node in Nodes) + clonedNodes.Add(node.Clone()); + return new MiniYaml(Value, clonedNodes); } public Dictionary ToDictionary() @@ -290,8 +293,15 @@ namespace OpenRA public static List FromStream(Stream s, string fileName = "", bool discardCommentsAndWhitespace = true, Dictionary stringPool = null) { + IEnumerable Lines(StreamReader reader) + { + string line; + while ((line = reader.ReadLine()) != null) + yield return line; + } + using (var reader = new StreamReader(s)) - return FromString(reader.ReadToEnd(), fileName, discardCommentsAndWhitespace, stringPool); + return FromLines(Lines(reader), fileName, discardCommentsAndWhitespace, stringPool); } public static List FromString(string text, string fileName = "", bool discardCommentsAndWhitespace = true, Dictionary stringPool = null) @@ -340,7 +350,7 @@ namespace OpenRA static List ResolveInherits(string key, MiniYaml node, Dictionary tree, Dictionary inherited) { - var resolved = new List(); + var resolved = new List(node.Nodes.Count); // Inheritance is tracked from parent->child, but not from child->parentsiblings. inherited = new Dictionary(inherited);