Add LongObjectHashMap and LongHashSet
Replace uses of LongHashtable and LongHashset with new implementations. Remove EntryBase, LongBaseHashtable, LongHashset, and LongHashtable as they are no longer used. LongObjectHashMap does not use Entry or EntryBase classes internally for storage so has much lower object churn and greater performance. LongHashSet is not as much of performance win for our use case but for general use is up to seventeen times faster than the old implementation and is in fact faster than alternatives from "high performance" java libraries. This is being added so that if someone tries to use it in the future in a place unrelated to its current use they don't accidentally end up with something slower than the Java collections HashSet implementation.
This commit is contained in:
@@ -11,20 +11,20 @@ import java.util.Set;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.util.LongHashset;
|
||||
import org.bukkit.craftbukkit.util.LongHashtable;
|
||||
import org.bukkit.craftbukkit.util.LongHashSet;
|
||||
import org.bukkit.craftbukkit.util.LongObjectHashMap;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
public class ChunkProviderServer implements IChunkProvider {
|
||||
|
||||
// CraftBukkit start
|
||||
public LongHashset unloadQueue = new LongHashset();
|
||||
public LongHashSet unloadQueue = new LongHashSet();
|
||||
public Chunk emptyChunk;
|
||||
public IChunkProvider chunkProvider; // CraftBukkit
|
||||
private IChunkLoader e;
|
||||
public boolean forceChunkLoad = false; // true -> false
|
||||
public LongHashtable<Chunk> chunks = new LongHashtable<Chunk>();
|
||||
public LongObjectHashMap<Chunk> chunks = new LongObjectHashMap<Chunk>();
|
||||
public List chunkList = new ArrayList();
|
||||
public WorldServer world;
|
||||
// CraftBukkit end
|
||||
|
||||
@@ -7,33 +7,14 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.util.LongBaseHashtable;
|
||||
import org.bukkit.craftbukkit.util.EntryBase;
|
||||
import org.bukkit.craftbukkit.util.LongObjectHashMap;
|
||||
import org.bukkit.craftbukkit.util.LongHash;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
// CraftBukkit end
|
||||
|
||||
public final class SpawnerCreature {
|
||||
// CraftBukkit start
|
||||
// private static HashMap b = new HashMap(); // Moved local to spawnEntities
|
||||
static private class ChunkEntry extends EntryBase {
|
||||
public boolean spawn;
|
||||
|
||||
public ChunkEntry(int x, int z, boolean spawn) {
|
||||
super(LongHash.toLong(x, z));
|
||||
this.spawn = spawn;
|
||||
}
|
||||
|
||||
int getX() {
|
||||
return LongHash.msw(key);
|
||||
}
|
||||
|
||||
int getZ() {
|
||||
return LongHash.lsw(key);
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
private static LongObjectHashMap b = new LongObjectHashMap(); // CraftBukkit - HashMap -> LongObjectHashMap
|
||||
protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class};
|
||||
|
||||
protected static ChunkPosition getRandomPosition(World world, int i, int j) {
|
||||
@@ -49,10 +30,7 @@ public final class SpawnerCreature {
|
||||
if (!flag && !flag1) {
|
||||
return 0;
|
||||
} else {
|
||||
// CraftBukkit start
|
||||
// b.clear();
|
||||
LongBaseHashtable chunkCoords = new LongBaseHashtable();
|
||||
// CraftBukkit end
|
||||
b.clear();
|
||||
|
||||
int i;
|
||||
int j;
|
||||
@@ -67,13 +45,14 @@ public final class SpawnerCreature {
|
||||
for (int l = -b0; l <= b0; ++l) {
|
||||
for (int i1 = -b0; i1 <= b0; ++i1) {
|
||||
boolean flag2 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0;
|
||||
|
||||
// CraftBukkit start
|
||||
long chunkCoord = LongHash.toLong(l + k, i1 + j);
|
||||
long chunkCoords = LongHash.toLong(l + k, i1 + j);
|
||||
|
||||
if (!flag2) {
|
||||
chunkCoords.put(new ChunkEntry(l + k, i1 + j, false));
|
||||
} else if (!chunkCoords.containsKey(chunkCoord)) {
|
||||
chunkCoords.put(new ChunkEntry(l + k, i1 + j, true));
|
||||
b.put(chunkCoords, false);
|
||||
} else if (!b.containsKey(chunkCoords)) {
|
||||
b.put(chunkCoords, true);
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
@@ -82,7 +61,6 @@ public final class SpawnerCreature {
|
||||
|
||||
i = 0;
|
||||
ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
|
||||
java.util.ArrayList<EntryBase> b = chunkCoords.entries(); // CraftBukkit
|
||||
EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values();
|
||||
|
||||
j = aenumcreaturetype.length;
|
||||
@@ -110,13 +88,15 @@ public final class SpawnerCreature {
|
||||
// CraftBukkit end
|
||||
|
||||
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && worldserver.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
|
||||
Iterator iterator = b.keySet().iterator();
|
||||
|
||||
// CraftBukkit start
|
||||
label108:
|
||||
for (EntryBase base : b) {
|
||||
ChunkEntry entry = (SpawnerCreature.ChunkEntry) base;
|
||||
if (!entry.spawn) {
|
||||
ChunkPosition chunkposition = getRandomPosition(worldserver, entry.getX(), entry.getZ());
|
||||
while (iterator.hasNext()) {
|
||||
// CraftBukkit start
|
||||
long key = ((Long) iterator.next()).longValue();
|
||||
|
||||
if (!((Boolean) b.get(key)).booleanValue()) {
|
||||
ChunkPosition chunkposition = getRandomPosition(worldserver, LongHash.msw(key), LongHash.lsw(key));
|
||||
// CraftBukkit end
|
||||
int k1 = chunkposition.x;
|
||||
int l1 = chunkposition.y;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.concurrent.Callable;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.util.LongHashset;
|
||||
import org.bukkit.craftbukkit.util.LongHashSet;
|
||||
import org.bukkit.craftbukkit.util.UnsafeList;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
@@ -60,7 +60,7 @@ public abstract class World implements IBlockAccess {
|
||||
// CraftBukkit start - public, longhashset
|
||||
public boolean allowMonsters = true;
|
||||
public boolean allowAnimals = true;
|
||||
protected LongHashset chunkTickList = new LongHashset();
|
||||
protected LongHashSet chunkTickList = new LongHashSet();
|
||||
public long ticksPerAnimalSpawns;
|
||||
public long ticksPerMonsterSpawns;
|
||||
// CraftBukkit end
|
||||
@@ -1057,12 +1057,12 @@ public abstract class World implements IBlockAccess {
|
||||
for (i = 0; i < this.j.size(); ++i) {
|
||||
entity = (Entity) this.j.get(i);
|
||||
// CraftBukkit start - fixed an NPE, don't process entities in chunks queued for unload
|
||||
ChunkProviderServer chunkProviderServer = ((WorldServer) entity.world).chunkProviderServer;
|
||||
if (chunkProviderServer.unloadQueue.containsKey(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
|
||||
if (entity == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
ChunkProviderServer chunkProviderServer = ((WorldServer) entity.world).chunkProviderServer;
|
||||
if (chunkProviderServer.unloadQueue.contains(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -1103,7 +1103,7 @@ public abstract class World implements IBlockAccess {
|
||||
|
||||
// CraftBukkit start - don't tick entities in chunks queued for unload
|
||||
ChunkProviderServer chunkProviderServer = ((WorldServer) entity.world).chunkProviderServer;
|
||||
if (chunkProviderServer.unloadQueue.containsKey(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
|
||||
if (chunkProviderServer.unloadQueue.contains(MathHelper.floor(entity.locX) >> 4, MathHelper.floor(entity.locZ) >> 4)) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -1147,7 +1147,7 @@ public abstract class World implements IBlockAccess {
|
||||
|
||||
// CraftBukkit start - don't tick entities in chunks queued for unload
|
||||
ChunkProviderServer chunkProviderServer = ((WorldServer) tileentity.world).chunkProviderServer;
|
||||
if (chunkProviderServer.unloadQueue.containsKey(tileentity.x >> 4, tileentity.z >> 4)) {
|
||||
if (chunkProviderServer.unloadQueue.contains(tileentity.x >> 4, tileentity.z >> 4)) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -1819,7 +1819,7 @@ public abstract class World implements IBlockAccess {
|
||||
for (int i1 = -b0; i1 <= b0; ++i1) {
|
||||
// CraftBukkit start - don't tick chunks queued for unload
|
||||
ChunkProviderServer chunkProviderServer = ((WorldServer) entityhuman.world).chunkProviderServer;
|
||||
if (chunkProviderServer.unloadQueue.containsKey(l + j, i1 + k)) {
|
||||
if (chunkProviderServer.unloadQueue.contains(l + j, i1 + k)) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
Reference in New Issue
Block a user