Fix unnecessary allocations with block properties function (#1387)

This commit is contained in:
Koding 2022-09-06 22:55:21 +10:00 committed by GitHub
parent b3d81f274c
commit 4a5736cc7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -165,6 +165,7 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
final PropertyType[] propertyTypes = PROPERTIES_TYPE.get(id());
assert propertyTypes != null;
final int length = propertyTypes.length;
if (length == 0) return Map.of();
String[] keys = new String[length];
String[] values = new String[length];
for (int i = 0; i < length; i++) {
@ -172,7 +173,7 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
keys[i] = property.key();
values[i] = property.values().get(propertiesArray[i]);
}
return Map.class.cast(Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(keys, values, length)));
return Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(keys, values, length));
}
@Override