diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 8702cdfe17..933af18c93 100755 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -142,7 +142,7 @@ namespace OpenRA return nd.ContainsKey(s) ? nd[s].Nodes : new List(); } - static List FromLines(string[] lines, string filename) + static List FromLines(IEnumerable lines, string filename) { var levels = new List>(); levels.Add(new List()); @@ -152,8 +152,9 @@ namespace OpenRA { var line = ll; ++lineNo; - if (line.Contains('#')) - line = line.Substring(0, line.IndexOf('#')).TrimEnd(' ', '\t'); + var commentIndex = line.IndexOf('#'); + if (commentIndex != -1) + line = line.Substring(0, commentIndex).TrimEnd(' ', '\t'); var t = line.TrimStart(' ', '\t'); if (t.Length == 0) continue; @@ -189,12 +190,8 @@ namespace OpenRA public static List FromFileInPackage(string path) { - var lines = new List(); using (var stream = GlobalFileSystem.Open(path)) - using (var reader = new StreamReader(stream)) - while (!reader.EndOfStream) - lines.Add(reader.ReadLine()); - return FromLines(lines.ToArray(), path); + return FromLines(stream.ReadAllLines(), path); } public static Dictionary DictFromFile(string path) diff --git a/OpenRA.Game/StreamExts.cs b/OpenRA.Game/StreamExts.cs index 5f504e27f8..ac89eedd4c 100755 --- a/OpenRA.Game/StreamExts.cs +++ b/OpenRA.Game/StreamExts.cs @@ -124,17 +124,10 @@ namespace OpenRA public static IEnumerable ReadAllLines(this Stream s) { + string line; using (var sr = new StreamReader(s)) - { - for (;;) - { - var line = sr.ReadLine(); - if (line == null) - yield break; - else - yield return line; - } - } + while ((line = sr.ReadLine()) != null) + yield return line; } // The string is assumed to be length-prefixed, as written by WriteString()