From 9afb86a5113c0d1e321e91ad3452fce97b80f684 Mon Sep 17 00:00:00 2001 From: TheMode Date: Tue, 17 Aug 2021 20:37:15 +0200 Subject: [PATCH] Use fastutil `#fastIterable` when possible --- .../server/instance/batch/AbsoluteBlockBatch.java | 11 +++-------- .../minestom/server/utils/entity/EntityFinder.java | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/batch/AbsoluteBlockBatch.java b/src/main/java/net/minestom/server/instance/batch/AbsoluteBlockBatch.java index b8f22fb22..91af487eb 100644 --- a/src/main/java/net/minestom/server/instance/batch/AbsoluteBlockBatch.java +++ b/src/main/java/net/minestom/server/instance/batch/AbsoluteBlockBatch.java @@ -1,6 +1,7 @@ package net.minestom.server.instance.batch; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; @@ -124,24 +125,20 @@ public class AbsoluteBlockBatch implements Batch { final AbsoluteBlockBatch inverse = this.options.shouldCalculateInverse() ? new AbsoluteBlockBatch(inverseOption) : null; synchronized (chunkBatchesMap) { AtomicInteger counter = new AtomicInteger(); - for (Long2ObjectMap.Entry entry : chunkBatchesMap.long2ObjectEntrySet()) { + for (var entry : Long2ObjectMaps.fastIterable(chunkBatchesMap)) { final long chunkIndex = entry.getLongKey(); final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex); final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex); final ChunkBatch batch = entry.getValue(); - ChunkBatch chunkInverse = batch.apply(instance, chunkX, chunkZ, c -> { final boolean isLast = counter.incrementAndGet() == chunkBatchesMap.size(); - // Execute the callback if this was the last chunk to process if (isLast) { if (inverse != null) inverse.readyLatch.countDown(); - if (instance instanceof InstanceContainer) { // FIXME: put method in Instance instead ((InstanceContainer) instance).refreshLastBlockChangeTime(); } - if (callback != null) { if (safeCallback) { instance.scheduleNextTick(inst -> callback.run()); @@ -151,9 +148,7 @@ public class AbsoluteBlockBatch implements Batch { } } }); - - if (inverse != null) - inverse.chunkBatchesMap.put(chunkIndex, chunkInverse); + if (inverse != null) inverse.chunkBatchesMap.put(chunkIndex, chunkInverse); } } diff --git a/src/main/java/net/minestom/server/utils/entity/EntityFinder.java b/src/main/java/net/minestom/server/utils/entity/EntityFinder.java index 5fff6e15b..b58085bcb 100644 --- a/src/main/java/net/minestom/server/utils/entity/EntityFinder.java +++ b/src/main/java/net/minestom/server/utils/entity/EntityFinder.java @@ -1,6 +1,6 @@ package net.minestom.server.utils.entity; -import it.unimi.dsi.fastutil.objects.Object2BooleanMap; +import it.unimi.dsi.fastutil.objects.Object2BooleanMaps; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import net.minestom.server.MinecraftServer; import net.minestom.server.command.CommandSender; @@ -358,7 +358,7 @@ public class EntityFinder { } private static boolean filterToggleableMap(@NotNull T value, @NotNull ToggleableMap map) { - for (Object2BooleanMap.Entry entry : map.object2BooleanEntrySet()) { + for (var entry : Object2BooleanMaps.fastIterable(map)) { if (entry.getBooleanValue() != Objects.equals(value, entry.getKey())) { return false; }