Avoid string allocations in MiniYaml parsing.
- Stream lines in as memory rather than needing to realise a string for each line, via a new method in StreamExts. - Use span to avoid string allocations during parsing until we want to realise the node itself, in MiniYaml.FromLines. - Change several callsites to use the streaming extension method rather than string method where possible.
This commit is contained in:
@@ -35,13 +35,9 @@ namespace OpenRA.Mods.Common.FileFormats
|
||||
|
||||
public void Load(Stream s)
|
||||
{
|
||||
var reader = new StreamReader(s);
|
||||
IniSection currentSection = null;
|
||||
|
||||
while (!reader.EndOfStream)
|
||||
foreach (var line in s.ReadAllLines())
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
|
||||
if (line.Length == 0) continue;
|
||||
|
||||
switch (line[0])
|
||||
|
||||
@@ -164,9 +164,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var httpClient = HttpClientFactory.Create();
|
||||
|
||||
var httpResponseMessage = await httpClient.GetAsync(playerDatabase.Profile + client.Fingerprint);
|
||||
var result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var result = await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||
|
||||
var yaml = MiniYaml.FromString(result).First();
|
||||
var yaml = MiniYaml.FromStream(result).First();
|
||||
if (yaml.Key == "Player")
|
||||
{
|
||||
profile = FieldLoader.Load<PlayerProfile>(yaml.Value);
|
||||
|
||||
@@ -346,13 +346,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var games = new List<GameServer>();
|
||||
var client = HttpClientFactory.Create();
|
||||
var httpResponseMessage = await client.GetAsync(queryURL);
|
||||
var result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var result = await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||
|
||||
activeQuery = true;
|
||||
|
||||
try
|
||||
{
|
||||
var yaml = MiniYaml.FromString(result);
|
||||
var yaml = MiniYaml.FromStream(result);
|
||||
foreach (var node in yaml)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user