Use jdk collections for registry storage

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-12-18 01:22:22 +01:00
parent 34785e96f3
commit 4008398058

View File

@ -2,8 +2,6 @@ package net.minestom.server.registry;
import com.google.gson.ToNumberPolicy; import com.google.gson.ToNumberPolicy;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.EntitySpawnType; import net.minestom.server.entity.EntitySpawnType;
import net.minestom.server.entity.EquipmentSlot; import net.minestom.server.entity.EquipmentSlot;
@ -535,18 +533,19 @@ public final class Registry {
private static Object readObject(JsonReader reader) throws IOException { private static Object readObject(JsonReader reader) throws IOException {
return switch (reader.peek()) { return switch (reader.peek()) {
case BEGIN_ARRAY -> { case BEGIN_ARRAY -> {
ObjectArrayList<Object> list = new ObjectArrayList<>(); ArrayList<Object> list = new ArrayList<>();
reader.beginArray(); reader.beginArray();
while (reader.hasNext()) list.add(readObject(reader)); while (reader.hasNext()) list.add(readObject(reader));
reader.endArray(); reader.endArray();
yield new ObjectArrayList<>(list); list.trimToSize();
yield list;
} }
case BEGIN_OBJECT -> { case BEGIN_OBJECT -> {
Object2ObjectArrayMap<String, Object> map = new Object2ObjectArrayMap<>(); Map<String, Object> map = new HashMap<>();
reader.beginObject(); reader.beginObject();
while (reader.hasNext()) map.put(reader.nextName().intern(), readObject(reader)); while (reader.hasNext()) map.put(reader.nextName().intern(), readObject(reader));
reader.endObject(); reader.endObject();
yield new Object2ObjectArrayMap<>(map); yield map;
} }
case STRING -> reader.nextString().intern(); case STRING -> reader.nextString().intern();
case NUMBER -> ToNumberPolicy.LONG_OR_DOUBLE.readNumber(reader); case NUMBER -> ToNumberPolicy.LONG_OR_DOUBLE.readNumber(reader);