Use collection copies

This commit is contained in:
themode 2021-12-19 00:26:20 +01:00 committed by TheMode
parent ba8667a361
commit 089a90df52
2 changed files with 3 additions and 4 deletions

View File

@ -20,7 +20,7 @@ final class BlockImpl implements Block {
private static final ObjectArray<Block> BLOCK_STATE_MAP = new ObjectArray<>(); private static final ObjectArray<Block> BLOCK_STATE_MAP = new ObjectArray<>();
private static final Registry.Container<Block> CONTAINER = new Registry.Container<>(Registry.Resource.BLOCKS, private static final Registry.Container<Block> CONTAINER = new Registry.Container<>(Registry.Resource.BLOCKS,
(container, namespace, object) -> { (container, namespace, object) -> {
final var stateObject = (Map<String, Object>) object.remove("states"); final var stateObject = (Map<String, Object>) object.get("states");
// Loop each state // Loop each state
var propertyEntry = new HashMap<Map<String, String>, Block>(); var propertyEntry = new HashMap<Map<String, String>, Block>();
var unmodifiableEntries = Collections.unmodifiableMap(propertyEntry); var unmodifiableEntries = Collections.unmodifiableMap(propertyEntry);

View File

@ -537,15 +537,14 @@ public final class Registry {
reader.beginArray(); reader.beginArray();
while (reader.hasNext()) list.add(readObject(reader)); while (reader.hasNext()) list.add(readObject(reader));
reader.endArray(); reader.endArray();
list.trimToSize(); yield List.copyOf(list);
yield list;
} }
case BEGIN_OBJECT -> { case BEGIN_OBJECT -> {
Map<String, Object> map = new HashMap<>(); 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 map; yield Map.copyOf(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);