Use a for-each loop, and prevent iterator allocation when empty

This commit is contained in:
TheMode 2021-06-15 02:29:58 +02:00
parent 051fbcb34b
commit 0c0b387345

View File

@ -133,7 +133,9 @@ public abstract class ThreadProvider {
if (!ChunkUtils.isLoaded(chunk))
return;
chunk.tick(time);
chunkEntry.entities.forEach(entity -> {
final var entities = chunkEntry.entities;
if (!entities.isEmpty()) {
for (Entity entity : entities) {
final boolean hasQueue = lock.hasQueuedThreads();
if (hasQueue) {
lock.unlock();
@ -141,7 +143,8 @@ public abstract class ThreadProvider {
lock.lock();
}
entity.tick(time);
});
}
}
});
Acquirable.refreshEntries(Collections.emptySet());
lock.unlock();