mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
Optimise CraftWorld#getLoadedChunks
We can use the existing full chunk map so that we do not need to iterate over all ChunkHolders. Additionally, do not use streams to do the iteration either.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
@VisibleForDebug
|
||||
private NaturalSpawner.SpawnState lastSpawnState;
|
||||
+ // Paper start
|
||||
+ private final ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<net.minecraft.world.level.chunk.LevelChunk> fullChunks = new ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<>();
|
||||
+ public final ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<net.minecraft.world.level.chunk.LevelChunk> fullChunks = new ca.spottedleaf.concurrentutil.map.ConcurrentLong2ReferenceChainedHashTable<>();
|
||||
+ public int getFullChunksCount() {
|
||||
+ return this.fullChunks.size();
|
||||
+ }
|
||||
|
@@ -421,8 +421,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
|
||||
@Override
|
||||
public Chunk[] getLoadedChunks() {
|
||||
List<ChunkHolder> chunks = ca.spottedleaf.moonrise.common.PlatformHooks.get().getVisibleChunkHolders(this.world); // Paper
|
||||
return chunks.stream().map(ChunkHolder::getFullChunkNow).filter(Objects::nonNull).map(CraftChunk::new).toArray(Chunk[]::new);
|
||||
// Paper start - optimise getLoadedChunks
|
||||
net.minecraft.server.level.ServerChunkCache serverChunkCache = this.getHandle().chunkSource;
|
||||
ca.spottedleaf.moonrise.common.list.ReferenceList<Chunk> chunks = new ca.spottedleaf.moonrise.common.list.ReferenceList<>(new Chunk[serverChunkCache.fullChunks.size()]);
|
||||
|
||||
for (java.util.PrimitiveIterator.OfLong iterator = serverChunkCache.fullChunks.keyIterator(); iterator.hasNext();) {
|
||||
long chunk = iterator.nextLong();
|
||||
chunks.add(new CraftChunk(this.world, ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(chunk), ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(chunk)));
|
||||
}
|
||||
|
||||
Chunk[] raw = chunks.getRawDataUnchecked();
|
||||
int size = chunks.size();
|
||||
if (raw.length == size) {
|
||||
// always true when on main
|
||||
return raw;
|
||||
}
|
||||
return java.util.Arrays.copyOf(raw, size);
|
||||
// Paper end - optimise getLoadedChunks
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user