From 0c0b387345e256aab47a8fb96069174056a572cf Mon Sep 17 00:00:00 2001 From: TheMode Date: Tue, 15 Jun 2021 02:29:58 +0200 Subject: [PATCH] Use a for-each loop, and prevent iterator allocation when empty --- .../server/thread/ThreadProvider.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/thread/ThreadProvider.java b/src/main/java/net/minestom/server/thread/ThreadProvider.java index ba937c085..54c32ca76 100644 --- a/src/main/java/net/minestom/server/thread/ThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/ThreadProvider.java @@ -133,15 +133,18 @@ public abstract class ThreadProvider { if (!ChunkUtils.isLoaded(chunk)) return; chunk.tick(time); - chunkEntry.entities.forEach(entity -> { - final boolean hasQueue = lock.hasQueuedThreads(); - if (hasQueue) { - lock.unlock(); - // #acquire callbacks should be called here - lock.lock(); + final var entities = chunkEntry.entities; + if (!entities.isEmpty()) { + for (Entity entity : entities) { + final boolean hasQueue = lock.hasQueuedThreads(); + if (hasQueue) { + lock.unlock(); + // #acquire callbacks should be called here + lock.lock(); + } + entity.tick(time); } - entity.tick(time); - }); + } }); Acquirable.refreshEntries(Collections.emptySet()); lock.unlock();