Paper/CraftBukkit-Patches/0022-Optimize-getTileEntities-performance.patch

45 Zeilen
1.9 KiB
Diff

2013-04-10 06:08:33 +02:00
From 8d27525a8a31f519e1a587af176fc9ec326c09e8 Mon Sep 17 00:00:00 2001
From: Mike Primm <mike@primmhome.com>
Date: Wed, 20 Feb 2013 23:07:53 -0500
Subject: [PATCH] Optimize getTileEntities performance
Avoid traversing tile entities for every loaded chunk
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 0abfc35..615968f 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -675,17 +675,20 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate
public List getTileEntities(int i, int j, int k, int l, int i1, int j1) {
ArrayList arraylist = new ArrayList();
2013-03-25 08:57:00 +01:00
- // CraftBukkit start - Use iterator
- Iterator iterator = this.tileEntityList.iterator();
-
- while (iterator.hasNext()) {
- TileEntity tileentity = (TileEntity) iterator.next();
- // CraftBukkit end
-
- if (tileentity.x >= i && tileentity.y >= j && tileentity.z >= k && tileentity.x < l && tileentity.y < i1 && tileentity.z < j1) {
- arraylist.add(tileentity);
+ // Spigot start - check in chunks: usually just from one
+ for (int cx = (i >> 4); cx <= ((l - 1) >> 4); cx++) {
+ for (int cz = (k >> 4); cz <= ((j1 - 1) >> 4); cz++) {
+ Chunk c = getChunkAt(cx, cz);
+ if (c == null) continue;
+ for (Object te : c.tileEntities.values()) {
+ TileEntity tileentity = (TileEntity) te;
+ if ((tileentity.x >= i) && (tileentity.y >= j) && (tileentity.z >= k) && (tileentity.x < l) && (tileentity.y < i1) && (tileentity.z < j1)) {
+ arraylist.add(tileentity);
+ }
+ }
}
}
+ // Spigot end
return arraylist;
}
--
1.8.2.1