mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Allocate even less
This commit is contained in:
parent
5acc894351
commit
7a66ba25c6
@ -13,12 +13,15 @@ namespace MCGalaxy.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public sealed class JsonArray : List<object> { }
|
public sealed class JsonArray : List<object> { }
|
||||||
public sealed class JsonObject : Dictionary<string, object> {
|
|
||||||
|
public sealed class JsonObject {
|
||||||
|
// NOTE: BlockDefinitions entries have about 30 members
|
||||||
|
public List<string> Keys = new List<string>(30);
|
||||||
|
public List<object> Values = new List<object>(30);
|
||||||
|
|
||||||
public void Deserialise(ConfigElement[] elems, object instance, string group) {
|
public void Deserialise(ConfigElement[] elems, object instance, string group) {
|
||||||
foreach (KeyValuePair<string, object> e in this) {
|
for (int i = 0; i < Keys.Count; i++) {
|
||||||
string key = e.Key, value = (string)e.Value;
|
ConfigElement.Parse(elems, group, instance, Keys[i], (string)Values[i]);
|
||||||
ConfigElement.Parse(elems, group, instance, key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +98,9 @@ namespace MCGalaxy.Config {
|
|||||||
token = NextToken(ctx);
|
token = NextToken(ctx);
|
||||||
if (token == T_NONE) { ctx.Success = false; return null; }
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,12 +111,13 @@ namespace MCGalaxy.Network {
|
|||||||
JsonObject obj = (JsonObject)Json.ParseStream(ctx);
|
JsonObject obj = (JsonObject)Json.ParseStream(ctx);
|
||||||
if (obj == null) return null;
|
if (obj == null) return null;
|
||||||
|
|
||||||
foreach (KeyValuePair<string, object> e in obj) {
|
for (int i = 0; i < obj.Keys.Count; i++) {
|
||||||
if (!e.Key.CaselessEq("errors")) continue;
|
if (!obj.Keys[i].CaselessEq("errors")) continue;
|
||||||
if (e.Value == null) return null;
|
object value = obj.Values[i];
|
||||||
|
if (value == null) return null;
|
||||||
|
|
||||||
// silly design, but form of json is: "errors": [ ["Error1"], ["Error2"] ]
|
// silly design, but form of json is: "errors": [ ["Error1"], ["Error2"] ]
|
||||||
JsonArray errors = (JsonArray)e.Value;
|
JsonArray errors = (JsonArray)value;
|
||||||
foreach (object raw in errors) {
|
foreach (object raw in errors) {
|
||||||
JsonArray error = raw as JsonArray;
|
JsonArray error = raw as JsonArray;
|
||||||
if (error != null && error.Count > 0) return (string)error[0];
|
if (error != null && error.Count > 0) return (string)error[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user