Merge pull request #7232 from RoosterDragon/yaml-parse-perf
Improve YAML parse time.
This commit is contained in:
@@ -142,7 +142,7 @@ namespace OpenRA
|
|||||||
return nd.ContainsKey(s) ? nd[s].Nodes : new List<MiniYamlNode>();
|
return nd.ContainsKey(s) ? nd[s].Nodes : new List<MiniYamlNode>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<MiniYamlNode> FromLines(string[] lines, string filename)
|
static List<MiniYamlNode> FromLines(IEnumerable<string> lines, string filename)
|
||||||
{
|
{
|
||||||
var levels = new List<List<MiniYamlNode>>();
|
var levels = new List<List<MiniYamlNode>>();
|
||||||
levels.Add(new List<MiniYamlNode>());
|
levels.Add(new List<MiniYamlNode>());
|
||||||
@@ -152,8 +152,9 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
var line = ll;
|
var line = ll;
|
||||||
++lineNo;
|
++lineNo;
|
||||||
if (line.Contains('#'))
|
var commentIndex = line.IndexOf('#');
|
||||||
line = line.Substring(0, line.IndexOf('#')).TrimEnd(' ', '\t');
|
if (commentIndex != -1)
|
||||||
|
line = line.Substring(0, commentIndex).TrimEnd(' ', '\t');
|
||||||
var t = line.TrimStart(' ', '\t');
|
var t = line.TrimStart(' ', '\t');
|
||||||
if (t.Length == 0)
|
if (t.Length == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -189,12 +190,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static List<MiniYamlNode> FromFileInPackage(string path)
|
public static List<MiniYamlNode> FromFileInPackage(string path)
|
||||||
{
|
{
|
||||||
var lines = new List<string>();
|
|
||||||
using (var stream = GlobalFileSystem.Open(path))
|
using (var stream = GlobalFileSystem.Open(path))
|
||||||
using (var reader = new StreamReader(stream))
|
return FromLines(stream.ReadAllLines(), path);
|
||||||
while (!reader.EndOfStream)
|
|
||||||
lines.Add(reader.ReadLine());
|
|
||||||
return FromLines(lines.ToArray(), path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, MiniYaml> DictFromFile(string path)
|
public static Dictionary<string, MiniYaml> DictFromFile(string path)
|
||||||
|
|||||||
@@ -124,17 +124,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static IEnumerable<string> ReadAllLines(this Stream s)
|
public static IEnumerable<string> ReadAllLines(this Stream s)
|
||||||
{
|
{
|
||||||
|
string line;
|
||||||
using (var sr = new StreamReader(s))
|
using (var sr = new StreamReader(s))
|
||||||
{
|
while ((line = sr.ReadLine()) != null)
|
||||||
for (;;)
|
yield return line;
|
||||||
{
|
|
||||||
var line = sr.ReadLine();
|
|
||||||
if (line == null)
|
|
||||||
yield break;
|
|
||||||
else
|
|
||||||
yield return line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The string is assumed to be length-prefixed, as written by WriteString()
|
// The string is assumed to be length-prefixed, as written by WriteString()
|
||||||
|
|||||||
Reference in New Issue
Block a user