mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 09:51:35 +01:00
Avoid block allocation if the properties map is the same
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
25055413ff
commit
e65c9f6a79
@ -92,9 +92,7 @@ final class BlockImpl implements Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Block withProperties(@NotNull Map<@NotNull String, @NotNull String> properties) {
|
public @NotNull Block withProperties(@NotNull Map<@NotNull String, @NotNull String> properties) {
|
||||||
if (properties.isEmpty()) {
|
if (properties.isEmpty()) return this;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
if (this.properties.size() == properties.size()) {
|
if (this.properties.size() == properties.size()) {
|
||||||
return compute(properties); // Map should be complete
|
return compute(properties); // Map should be complete
|
||||||
}
|
}
|
||||||
@ -171,6 +169,7 @@ final class BlockImpl implements Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Block compute(Map<String, String> properties) {
|
private Block compute(Map<String, String> properties) {
|
||||||
|
if (this.properties.equals(properties)) return this;
|
||||||
Block block = propertyEntry.get(properties);
|
Block block = propertyEntry.get(properties);
|
||||||
if (block == null)
|
if (block == null)
|
||||||
throw new IllegalArgumentException("Invalid properties: " + properties + " for block " + this);
|
throw new IllegalArgumentException("Invalid properties: " + properties + " for block " + this);
|
||||||
|
Loading…
Reference in New Issue
Block a user