Optimize iteration in reference chunk loader
This commit is contained in:
+34
-23
@@ -218,34 +218,45 @@ public class ReferenceCountingChunkLoader {
|
|||||||
|
|
||||||
final ReferenceCountData[] toRemoveTicket = new ReferenceCountData[1];
|
final ReferenceCountData[] toRemoveTicket = new ReferenceCountData[1];
|
||||||
|
|
||||||
for (ConcurrentChainedLong2ReferenceHashTable.TableEntry<ReferenceCountData> counterEntry : this.referenceCounters.entrySet()) {
|
final it.unimi.dsi.fastutil.longs.LongIterator sectionsIterator = currentRegion.getOwnedSectionsUnsynchronised();
|
||||||
final long coord = counterEntry.getKey();
|
while (sectionsIterator.hasNext()) {
|
||||||
final ReferenceCountData counterData = counterEntry.getValue();
|
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;
|
||||||
long curr = counterData.referenceTTL.get();
|
final int chunkZ = sectionZ << this.world.regioniser.sectionChunkShift;
|
||||||
if (curr == (curr = counterData.referenceTTL.compareAndExchange(curr, curr - 1))) {
|
final long coord = CoordinateUtils.getChunkKey(chunkX, chunkZ);
|
||||||
if (counterData.referenceCount.get() != 0L) {
|
final ReferenceCountData counterData = this.referenceCounters.get(coord);
|
||||||
counterData.referenceTTL.set(MAX_CHUNK_TTL_TICKS);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curr <= 0) {
|
// removed
|
||||||
this.referenceCounters.computeIfPresent(coord, (final long keyInMap, final ReferenceCountData valueInMap) -> {
|
if (counterData == null) {
|
||||||
if (valueInMap.referenceCount.get() != 0L) {
|
continue;
|
||||||
valueInMap.referenceTTL.set(MAX_CHUNK_TTL_TICKS);
|
}
|
||||||
return valueInMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
toRemoveTicket[0] = valueInMap;
|
// do ttl
|
||||||
|
long curr = counterData.referenceTTL.get();
|
||||||
|
if (curr == (curr = counterData.referenceTTL.compareAndExchange(curr, curr - 1))) {
|
||||||
|
if (counterData.referenceCount.get() != 0L) {
|
||||||
|
counterData.referenceTTL.set(MAX_CHUNK_TTL_TICKS);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
if (curr <= 0) {
|
||||||
});
|
this.referenceCounters.computeIfPresent(coord, (final long keyInMap, final ReferenceCountData valueInMap) -> {
|
||||||
|
if (valueInMap.referenceCount.get() != 0L) {
|
||||||
if (toRemoveTicket[0] != null) {
|
valueInMap.referenceTTL.set(MAX_CHUNK_TTL_TICKS);
|
||||||
this.removeTicket(coord, toRemoveTicket[0].id);
|
return valueInMap;
|
||||||
toRemoveTicket[0] = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toRemoveTicket[0] = valueInMap;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (toRemoveTicket[0] != null) {
|
||||||
|
this.removeTicket(coord, toRemoveTicket[0].id);
|
||||||
|
toRemoveTicket[0] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user