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

110 Zeilen
4.9 KiB
Diff

2015-02-28 12:36:22 +01:00
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
2015-02-28 12:36:22 +01:00
index 044a09d..b7d09a9 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2015-02-28 12:36:22 +01:00
@@ -16,8 +16,11 @@ import org.apache.logging.log4j.Logger;
public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
private static final Logger a = LogManager.getLogger();
2015-02-28 12:36:22 +01:00
- private List<ChunkRegionLoader.PendingChunkToSave> b = Lists.newArrayList();
- private Set<ChunkCoordIntPair> c = Sets.newHashSet();
2014-11-28 02:17:45 +01:00
+ // Spigot start
+ private java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave>();
2015-02-28 12:36:22 +01:00
+ // private List<ChunkRegionLoader.PendingChunkToSave> b = Lists.newArrayList();
+ // private Set<ChunkCoordIntPair> c = Sets.newHashSet();
2014-11-28 02:17:45 +01:00
+ // Spigot end
private Object d = new Object();
private final File e;
2015-02-28 12:36:22 +01:00
@@ -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);
2015-02-28 12:36:22 +01:00
@@ -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) {
2015-02-28 12:36:22 +01:00
- 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) {
2015-02-28 12:36:22 +01:00
@@ -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) {
2015-02-28 12:36:22 +01:00
- 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;
}
2014-11-28 02:17:45 +01:00
2015-02-28 12:36:22 +01:00
- this.b.add(new ChunkRegionLoader.PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- this.c.add(chunkcoordintpair);
2015-02-28 12:36:22 +01:00
+ // this.b.add(new ChunkRegionLoader.PendingChunkToSave(chunkcoordintpair, nbttagcompound));
2014-11-28 02:17:45 +01:00
+ // this.c.add(chunkcoordintpair);
+ // Spigot end
2014-11-28 02:17:45 +01:00
FileIOThread.a().a(this);
}
}
2015-02-28 12:36:22 +01:00
@@ -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;
}
2015-02-28 12:36:22 +01:00
- 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
}
2015-02-28 12:36:22 +01:00
if (chunkregionloader_pendingchunktosave != null) {
--
2014-11-28 02:17:45 +01:00
2.1.0