mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 07:02:32 +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 com.google.gson.JsonObject;
|
||||||
import net.minestom.server.registry.Registry;
|
import net.minestom.server.registry.Registry;
|
||||||
|
import net.minestom.server.utils.StringUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -80,7 +82,11 @@ class BlockRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, String> getPropertyMap(String query) {
|
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);
|
final String propertiesString = query.substring(1);
|
||||||
StringBuilder keyBuilder = new StringBuilder();
|
StringBuilder keyBuilder = new StringBuilder();
|
||||||
StringBuilder valueBuilder = new StringBuilder();
|
StringBuilder valueBuilder = new StringBuilder();
|
||||||
|
@ -14,27 +14,22 @@ import java.util.Objects;
|
|||||||
class BlockTest implements Block {
|
class BlockTest implements Block {
|
||||||
|
|
||||||
private final Registry.BlockEntry registry;
|
private final Registry.BlockEntry registry;
|
||||||
|
|
||||||
private final Map<String, String> properties;
|
private final Map<String, String> properties;
|
||||||
private final NBTCompound compound;
|
private final NBTCompound compound;
|
||||||
private final BlockHandler handler;
|
private final BlockHandler handler;
|
||||||
|
|
||||||
private final Map<String, String> unmodifiableProperties;
|
BlockTest(@NotNull Registry.BlockEntry registry,
|
||||||
|
@NotNull Map<String, String> properties,
|
||||||
BlockTest(Registry.BlockEntry registry,
|
@Nullable NBTCompound compound,
|
||||||
Map<String, String> properties,
|
@Nullable BlockHandler handler) {
|
||||||
NBTCompound compound,
|
|
||||||
BlockHandler handler) {
|
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
this.properties = properties;
|
this.properties = Collections.unmodifiableMap(properties);
|
||||||
this.compound = compound;
|
this.compound = compound;
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
|
||||||
this.unmodifiableProperties = Collections.unmodifiableMap(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockTest(Registry.BlockEntry registry,
|
BlockTest(@NotNull Registry.BlockEntry registry,
|
||||||
Map<String, String> properties) {
|
@NotNull Map<String, String> properties) {
|
||||||
this(registry, properties, null, null);
|
this(registry, properties, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +63,7 @@ class BlockTest implements Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, String> getProperties() {
|
public @NotNull Map<String, String> getProperties() {
|
||||||
return unmodifiableProperties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user