From e65c9f6a79f281223ce27e77050ba597a7a4173d Mon Sep 17 00:00:00 2001 From: TheMode Date: Mon, 20 Sep 2021 18:09:16 +0200 Subject: [PATCH] Avoid block allocation if the properties map is the same Signed-off-by: TheMode --- .../java/net/minestom/server/instance/block/BlockImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/block/BlockImpl.java b/src/main/java/net/minestom/server/instance/block/BlockImpl.java index a39048b62..7380e511f 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockImpl.java +++ b/src/main/java/net/minestom/server/instance/block/BlockImpl.java @@ -92,9 +92,7 @@ final class BlockImpl implements Block { @Override public @NotNull Block withProperties(@NotNull Map<@NotNull String, @NotNull String> properties) { - if (properties.isEmpty()) { - return this; - } + if (properties.isEmpty()) return this; if (this.properties.size() == properties.size()) { return compute(properties); // Map should be complete } @@ -171,6 +169,7 @@ final class BlockImpl implements Block { } private Block compute(Map properties) { + if (this.properties.equals(properties)) return this; Block block = propertyEntry.get(properties); if (block == null) throw new IllegalArgumentException("Invalid properties: " + properties + " for block " + this);