From 7a66ba25c6813acc19feb5bd51d7ee3d3b1dff04 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 19 Jul 2018 20:34:12 +1000 Subject: [PATCH] Allocate even less --- MCGalaxy/Config/JSON.cs | 15 ++++++++++----- MCGalaxy/Network/Heartbeat/ClassiCube.cs | 9 +++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/MCGalaxy/Config/JSON.cs b/MCGalaxy/Config/JSON.cs index 209a85fda..ed814cb7a 100644 --- a/MCGalaxy/Config/JSON.cs +++ b/MCGalaxy/Config/JSON.cs @@ -13,12 +13,15 @@ namespace MCGalaxy.Config { } public sealed class JsonArray : List { } - public sealed class JsonObject : Dictionary { + + public sealed class JsonObject { + // NOTE: BlockDefinitions entries have about 30 members + public List Keys = new List(30); + public List Values = new List(30); public void Deserialise(ConfigElement[] elems, object instance, string group) { - foreach (KeyValuePair e in this) { - string key = e.Key, value = (string)e.Value; - ConfigElement.Parse(elems, group, instance, key, value); + for (int i = 0; i < Keys.Count; i++) { + ConfigElement.Parse(elems, group, instance, Keys[i], (string)Values[i]); } } } @@ -95,7 +98,9 @@ namespace MCGalaxy.Config { token = NextToken(ctx); if (token == T_NONE) { ctx.Success = false; return null; } - members[key] = ParseValue(token, ctx); + object value = ParseValue(token, ctx); + members.Keys.Add(key); + members.Values.Add(value); } } diff --git a/MCGalaxy/Network/Heartbeat/ClassiCube.cs b/MCGalaxy/Network/Heartbeat/ClassiCube.cs index 3b122d0d3..ace9eec4f 100644 --- a/MCGalaxy/Network/Heartbeat/ClassiCube.cs +++ b/MCGalaxy/Network/Heartbeat/ClassiCube.cs @@ -111,12 +111,13 @@ namespace MCGalaxy.Network { JsonObject obj = (JsonObject)Json.ParseStream(ctx); if (obj == null) return null; - foreach (KeyValuePair e in obj) { - if (!e.Key.CaselessEq("errors")) continue; - if (e.Value == null) return null; + for (int i = 0; i < obj.Keys.Count; i++) { + if (!obj.Keys[i].CaselessEq("errors")) continue; + object value = obj.Values[i]; + if (value == null) return null; // silly design, but form of json is: "errors": [ ["Error1"], ["Error2"] ] - JsonArray errors = (JsonArray)e.Value; + JsonArray errors = (JsonArray)value; foreach (object raw in errors) { JsonArray error = raw as JsonArray; if (error != null && error.Count > 0) return (string)error[0];