PaperSpigot-Parent/CraftBukkit-Patches/0008-More-Efficient-Chunk-Save-Queue.patch
2015-03-08 05:03:19 -05:00

110 lines
4.9 KiB
Diff

From a343b092ffaac6e336eef36fac78bb6ad4962d1c Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Tue, 11 Jun 2013 12:09:45 +1000
Subject: [PATCH] More Efficient Chunk Save Queue
Optimizes the data structures behind the chunk save queue into ones more suitable for the type of data and access which they are used for.
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index 044a09d..b7d09a9 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -16,8 +16,11 @@ import org.apache.logging.log4j.Logger;
public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
private static final Logger a = LogManager.getLogger();
- private List<ChunkRegionLoader.PendingChunkToSave> b = Lists.newArrayList();
- private Set<ChunkCoordIntPair> c = Sets.newHashSet();
+ // Spigot start
+ private java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave>();
+ // private List<ChunkRegionLoader.PendingChunkToSave> b = Lists.newArrayList();
+ // private Set<ChunkCoordIntPair> c = Sets.newHashSet();
+ // Spigot end
private Object d = new Object();
private final File e;
@@ -30,13 +33,11 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
synchronized (this.d) {
- if (this.c.contains(chunkcoordintpair)) {
- for (int k = 0; k < this.b.size(); ++k) {
- if (((PendingChunkToSave) this.b.get(k)).a.equals(chunkcoordintpair)) {
- return true;
- }
- }
- }
+ // Spigot start
+ if (pendingSaves.containsKey(chunkcoordintpair)) {
+ return true;
+ }
+ // Spigot end
}
return RegionFileCache.a(this.e, i, j).chunkExists(i & 31, j & 31);
@@ -63,14 +64,12 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
Object object = this.d;
synchronized (this.d) {
- if (this.c.contains(chunkcoordintpair)) {
- for (int k = 0; k < this.b.size(); ++k) {
- if (((ChunkRegionLoader.PendingChunkToSave) this.b.get(k)).a.equals(chunkcoordintpair)) {
- nbttagcompound = ((ChunkRegionLoader.PendingChunkToSave) this.b.get(k)).b;
- break;
- }
- }
+ // Spigot start
+ PendingChunkToSave pendingchunktosave = pendingSaves.get(chunkcoordintpair);
+ if (pendingchunktosave != null) {
+ nbttagcompound = pendingchunktosave.b;
}
+ // Spigot end
}
if (nbttagcompound == null) {
@@ -149,17 +148,14 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
Object object = this.d;
synchronized (this.d) {
- if (this.c.contains(chunkcoordintpair)) {
- for (int i = 0; i < this.b.size(); ++i) {
- if (((ChunkRegionLoader.PendingChunkToSave) this.b.get(i)).a.equals(chunkcoordintpair)) {
- this.b.set(i, new ChunkRegionLoader.PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- return;
- }
- }
+ // Spigot start
+ if (this.pendingSaves.put(chunkcoordintpair, new PendingChunkToSave(chunkcoordintpair, nbttagcompound)) != null) {
+ return;
}
- this.b.add(new ChunkRegionLoader.PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- this.c.add(chunkcoordintpair);
+ // this.b.add(new ChunkRegionLoader.PendingChunkToSave(chunkcoordintpair, nbttagcompound));
+ // this.c.add(chunkcoordintpair);
+ // Spigot end
FileIOThread.a().a(this);
}
}
@@ -169,12 +165,14 @@ public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
Object object = this.d;
synchronized (this.d) {
- if (this.b.isEmpty()) {
+ // Spigot start
+ if (this.pendingSaves.isEmpty()) {
return false;
}
- chunkregionloader_pendingchunktosave = (ChunkRegionLoader.PendingChunkToSave) this.b.remove(0);
- this.c.remove(chunkregionloader_pendingchunktosave.a);
+ chunkregionloader_pendingchunktosave = this.pendingSaves.values().iterator().next();
+ this.pendingSaves.remove(chunkregionloader_pendingchunktosave.a);
+ // Spigot end
}
if (chunkregionloader_pendingchunktosave != null) {
--
2.1.0