mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-24 16:22:06 +01:00
Avoid more allocation
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
a7971bf343
commit
32d692a56a
@ -68,11 +68,9 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
|
||||
final String query = stateEntry.getKey();
|
||||
final var stateOverride = (Map<String, Object>) stateEntry.getValue();
|
||||
final var propertyMap = BlockUtils.parseProperties(query);
|
||||
|
||||
assert keys.length == propertyMap.size();
|
||||
int[] propertiesArray = new int[keys.length];
|
||||
int i = 0;
|
||||
for (var entry : propertyMap.entrySet()) {
|
||||
final int entryIndex = i++;
|
||||
final int keyIndex = ArrayUtils.indexOf(keys, entry.getKey());
|
||||
if (keyIndex == -1) {
|
||||
throw new IllegalArgumentException("Unknown property key: " + entry.getKey());
|
||||
@ -81,7 +79,7 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
|
||||
if (valueIndex == -1) {
|
||||
throw new IllegalArgumentException("Unknown property value: " + entry.getValue());
|
||||
}
|
||||
propertiesArray[entryIndex] = valueIndex;
|
||||
propertiesArray[keyIndex] = valueIndex;
|
||||
}
|
||||
|
||||
final BlockImpl block = new BlockImpl(Registry.block(namespace, object, stateOverride),
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.minestom.server.utils.block;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -88,7 +88,7 @@ public class BlockUtils {
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return ArrayUtils.toMap(keys, values, entryCount);
|
||||
return new Object2ObjectArrayMap<>(keys, values, entryCount);
|
||||
}
|
||||
|
||||
public static @Nullable NBTCompound extractClientNbt(@NotNull Block block) {
|
||||
|
Loading…
Reference in New Issue
Block a user