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

110 Zeilen
4.5 KiB
Diff

From 6d0c5cae337957d4c1b3d8b5ff8eb01385433532 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
2014-11-28 02:17:45 +01:00
index a5175fd..9ab0b5e 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
2014-11-28 02:17:45 +01:00
@@ -15,8 +15,11 @@ import org.apache.logging.log4j.Logger;
public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
private static final Logger a = LogManager.getLogger();
2014-11-28 02:17:45 +01:00
- private List b = Lists.newArrayList();
- private Set c = Sets.newHashSet();
+ // Spigot start
+ private java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, PendingChunkToSave>();
+ // private List b = Lists.newArrayList();
+ // private Set c = Sets.newHashSet();
+ // Spigot end
private Object d = new Object();
private final File e;
@@ -29,13 +32,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);
2014-11-28 02:17:45 +01:00
@@ -62,14 +63,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 (((PendingChunkToSave) this.b.get(k)).a.equals(chunkcoordintpair)) {
- nbttagcompound = ((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) {
2014-11-28 02:17:45 +01:00
@@ -150,17 +149,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 (((PendingChunkToSave) this.b.get(i)).a.equals(chunkcoordintpair)) {
- this.b.set(i, new 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
- this.b.add(new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
- this.c.add(chunkcoordintpair);
2014-11-28 02:17:45 +01:00
+ // this.b.add(new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
+ // this.c.add(chunkcoordintpair);
+ // Spigot end
2014-11-28 02:17:45 +01:00
FileIOThread.a().a(this);
}
}
2014-11-28 02:17:45 +01:00
@@ -170,12 +166,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;
}
- pendingchunktosave = (PendingChunkToSave) this.b.remove(0);
- this.c.remove(pendingchunktosave.a);
+ pendingchunktosave = this.pendingSaves.values().iterator().next();
+ this.pendingSaves.remove(pendingchunktosave.a);
+ // Spigot end
}
if (pendingchunktosave != null) {
--
2014-11-28 02:17:45 +01:00
2.1.0