Optimize iteration in reference chunk loader
This commit is contained in:
+16
-5
@@ -218,11 +218,23 @@ public class ReferenceCountingChunkLoader {
|
||||
|
||||
final ReferenceCountData[] toRemoveTicket = new ReferenceCountData[1];
|
||||
|
||||
for (ConcurrentChainedLong2ReferenceHashTable.TableEntry<ReferenceCountData> counterEntry : this.referenceCounters.entrySet()) {
|
||||
final long coord = counterEntry.getKey();
|
||||
final ReferenceCountData counterData = counterEntry.getValue();
|
||||
final it.unimi.dsi.fastutil.longs.LongIterator sectionsIterator = currentRegion.getOwnedSectionsUnsynchronised();
|
||||
while (sectionsIterator.hasNext()) {
|
||||
final long sectionKey = sectionsIterator.nextLong();
|
||||
final int sectionX = CoordinateUtils.getChunkX(sectionKey);
|
||||
final int sectionZ = CoordinateUtils.getChunkZ(sectionKey);
|
||||
|
||||
if (currentRegion == this.world.regioniser.getRegionAtUnsynchronised(CoordinateUtils.getChunkX(coord), CoordinateUtils.getChunkZ(coord))) {
|
||||
final int chunkX = sectionX << this.world.regioniser.sectionChunkShift;
|
||||
final int chunkZ = sectionZ << this.world.regioniser.sectionChunkShift;
|
||||
final long coord = CoordinateUtils.getChunkKey(chunkX, chunkZ);
|
||||
final ReferenceCountData counterData = this.referenceCounters.get(coord);
|
||||
|
||||
// removed
|
||||
if (counterData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// do ttl
|
||||
long curr = counterData.referenceTTL.get();
|
||||
if (curr == (curr = counterData.referenceTTL.compareAndExchange(curr, curr - 1))) {
|
||||
if (counterData.referenceCount.get() != 0L) {
|
||||
@@ -250,7 +262,6 @@ public class ReferenceCountingChunkLoader {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ReferenceCountData {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user