mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Reduce property map allocation
This commit is contained in:
parent
06ebb14991
commit
61bd28b298
@ -2,9 +2,11 @@ package net.minestom.server.instance.block;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minestom.server.registry.Registry;
|
||||
import net.minestom.server.utils.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -80,7 +82,11 @@ class BlockRegistry {
|
||||
}
|
||||
|
||||
private static Map<String, String> getPropertyMap(String query) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
if (query.equals("[]")) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
final int capacity = StringUtils.countMatches(query, ',') + 1;
|
||||
Map<String, String> result = new HashMap<>(capacity);
|
||||
final String propertiesString = query.substring(1);
|
||||
StringBuilder keyBuilder = new StringBuilder();
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
|
@ -14,27 +14,22 @@ import java.util.Objects;
|
||||
class BlockTest implements Block {
|
||||
|
||||
private final Registry.BlockEntry registry;
|
||||
|
||||
private final Map<String, String> properties;
|
||||
private final NBTCompound compound;
|
||||
private final BlockHandler handler;
|
||||
|
||||
private final Map<String, String> unmodifiableProperties;
|
||||
|
||||
BlockTest(Registry.BlockEntry registry,
|
||||
Map<String, String> properties,
|
||||
NBTCompound compound,
|
||||
BlockHandler handler) {
|
||||
BlockTest(@NotNull Registry.BlockEntry registry,
|
||||
@NotNull Map<String, String> properties,
|
||||
@Nullable NBTCompound compound,
|
||||
@Nullable BlockHandler handler) {
|
||||
this.registry = registry;
|
||||
this.properties = properties;
|
||||
this.properties = Collections.unmodifiableMap(properties);
|
||||
this.compound = compound;
|
||||
this.handler = handler;
|
||||
|
||||
this.unmodifiableProperties = Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
BlockTest(Registry.BlockEntry registry,
|
||||
Map<String, String> properties) {
|
||||
BlockTest(@NotNull Registry.BlockEntry registry,
|
||||
@NotNull Map<String, String> properties) {
|
||||
this(registry, properties, null, null);
|
||||
}
|
||||
|
||||
@ -68,7 +63,7 @@ class BlockTest implements Block {
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, String> getProperties() {
|
||||
return unmodifiableProperties;
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user