Paper/CraftBukkit-Patches/0007-More-Efficient-Chunk-Save-Queue.patch

103 lines
4.1 KiB
Diff
Raw Normal View History

From 675e36fe50d76fed89733d50e4aa8dd9e77d9bae Mon Sep 17 00:00:00 2001
2013-06-11 04:10:31 +02:00
From: md_5 <md_5@live.com.au>
Date: Tue, 11 Jun 2013 12:09:45 +1000
Subject: [PATCH] More Efficient Chunk Save Queue
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2013-06-11 04:13:28 +02:00
index bee715b..5c67fe4 100644
2013-06-11 04:10:31 +02:00
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2013-06-11 04:13:28 +02:00
@@ -13,8 +13,7 @@ import java.util.Set;
2013-06-11 04:10:31 +02:00
public class ChunkRegionLoader implements IAsyncChunkSaver, IChunkLoader {
- private List a = new ArrayList();
- private Set b = new HashSet();
2013-06-11 04:13:28 +02:00
+ private java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave>(); // Spigot
2013-06-11 04:10:31 +02:00
private Object c = new Object();
private final File d;
2013-06-11 04:13:28 +02:00
@@ -27,13 +26,11 @@ public class ChunkRegionLoader implements IAsyncChunkSaver, IChunkLoader {
2013-06-11 04:10:31 +02:00
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
synchronized (this.c) {
- if (this.b.contains(chunkcoordintpair)) {
- for (int k = 0; k < this.a.size(); ++k) {
- if (((PendingChunkToSave) this.a.get(k)).a.equals(chunkcoordintpair)) {
- return true;
- }
- }
- }
+ // Spigot start
+ if (pendingSaves.containsKey(chunkcoordintpair)) {
+ return true;
+ }
+ // Spigot end
}
return RegionFileCache.a(this.d, i, j).chunkExists(i & 31, j & 31);
2013-06-11 04:13:28 +02:00
@@ -60,14 +57,12 @@ public class ChunkRegionLoader implements IAsyncChunkSaver, IChunkLoader {
2013-06-11 04:10:31 +02:00
Object object = this.c;
synchronized (this.c) {
- if (this.b.contains(chunkcoordintpair)) {
- for (int k = 0; k < this.a.size(); ++k) {
- if (((PendingChunkToSave) this.a.get(k)).a.equals(chunkcoordintpair)) {
- nbttagcompound = ((PendingChunkToSave) this.a.get(k)).b;
- break;
- }
- }
+ // Spigot start
+ PendingChunkToSave pendingchunktosave = pendingSaves.get(chunkcoordintpair);
+ if (pendingchunktosave != null) {
+ nbttagcompound = pendingchunktosave.b;
}
+ // Spigot end
}
if (nbttagcompound == null) {
2013-06-11 04:13:28 +02:00
@@ -148,17 +143,11 @@ public class ChunkRegionLoader implements IAsyncChunkSaver, IChunkLoader {
2013-06-11 04:10:31 +02:00
Object object = this.c;
synchronized (this.c) {
- if (this.b.contains(chunkcoordintpair)) {
- for (int i = 0; i < this.a.size(); ++i) {
- if (((PendingChunkToSave) this.a.get(i)).a.equals(chunkcoordintpair)) {
- this.a.set(i, new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- return;
- }
- }
+ // Spigot start
+ if (this.pendingSaves.put(chunkcoordintpair, new PendingChunkToSave(chunkcoordintpair, nbttagcompound)) != null) {
+ return;
}
-
- this.a.add(new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- this.b.add(chunkcoordintpair);
+ // Spigot end
FileIOThread.a.a(this);
}
}
2013-06-11 04:13:28 +02:00
@@ -168,12 +157,14 @@ public class ChunkRegionLoader implements IAsyncChunkSaver, IChunkLoader {
2013-06-11 04:10:31 +02:00
Object object = this.c;
synchronized (this.c) {
- if (this.a.isEmpty()) {
+ // Spigot start
+ if (this.pendingSaves.isEmpty()) {
return false;
}
- pendingchunktosave = (PendingChunkToSave) this.a.remove(0);
- this.b.remove(pendingchunktosave.a);
+ pendingchunktosave = this.pendingSaves.values().iterator().next();
+ this.pendingSaves.remove(pendingchunktosave.a);
+ // Spigot end
}
if (pendingchunktosave != null) {
--
1.8.1.2