Paper/Spigot-Server-Patches/0079-Optimize-NavigationListener-Iteration.patch
Aikar 017c6f73be Optimize NavigationListener Iteration
I don't know what the person who wrote that code was smoking, but I
don't think it was good.

Gets rid of the WeakHashMap that mojang was abusing purely to be lazy
on clean up, and handles registering and deregistering navigation
upon world add/remove operations.
2016-03-08 00:42:48 -05:00

101 Zeilen
4.3 KiB
Diff

From 9c96f51c8068de370baeb9fa4aee91c82d273e42 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 7 Mar 2016 22:43:26 -0500
Subject: [PATCH] Optimize NavigationListener Iteration
I don't know what the person who wrote that code was smoking, but I
don't think it was good.
Gets rid of the WeakHashMap that mojang was abusing purely to be lazy
on clean up, and handles registering and deregistering navigation
upon world add/remove operations.
diff --git a/src/main/java/net/minecraft/server/NavigationAbstract.java b/src/main/java/net/minecraft/server/NavigationAbstract.java
index 7d794b9..ca4cb26 100644
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java
+++ b/src/main/java/net/minecraft/server/NavigationAbstract.java
@@ -32,7 +32,7 @@ public abstract class NavigationAbstract {
this.b = world;
this.g = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
this.s = this.a();
- this.b.C().a(this);
+ //this.b.C().a(this); // Paper
}
protected abstract Pathfinder a();
diff --git a/src/main/java/net/minecraft/server/NavigationListener.java b/src/main/java/net/minecraft/server/NavigationListener.java
index f82ea80..ef446fc 100644
--- a/src/main/java/net/minecraft/server/NavigationListener.java
+++ b/src/main/java/net/minecraft/server/NavigationListener.java
@@ -1,26 +1,41 @@
package net.minecraft.server;
+import java.util.ArrayList; // Paper
+import java.util.List; // Paper
import java.util.WeakHashMap;
public class NavigationListener implements IWorldAccess {
private static final Object a = new Object();
- private final WeakHashMap<NavigationAbstract, Object> b = new WeakHashMap();
+ private final List<NavigationAbstract> navigators = new ArrayList<>(); // Paper
public NavigationListener() {}
+
public void a(NavigationAbstract navigationabstract) {
- this.b.put(navigationabstract, NavigationListener.a);
+ this.add(navigationabstract); // Paper
}
+ // Paper start
+ public void add(NavigationAbstract navigationabstract) {
+ this.navigators.add(navigationabstract);
+ }
+ public void remove(NavigationAbstract navigationabstract) {
+ this.navigators.remove(navigationabstract);
+ }
+ // Paper end
+
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, int i) {
if (this.a(world, blockposition, iblockdata, iblockdata1)) {
- NavigationAbstract[] anavigationabstract = (NavigationAbstract[]) this.b.keySet().toArray(new NavigationAbstract[0]);
- NavigationAbstract[] anavigationabstract1 = anavigationabstract;
- int j = anavigationabstract.length;
+ // Paper start
+ //NavigationAbstract[] anavigationabstract = (NavigationAbstract[]) this.navigators.keySet().toArray(new NavigationAbstract[0]);
+ //NavigationAbstract[] anavigationabstract1 = anavigationabstract;
+ int j = this.navigators.size();
+
for (int k = 0; k < j; ++k) {
- NavigationAbstract navigationabstract = anavigationabstract1[k];
+ NavigationAbstract navigationabstract = this.navigators.get(k);
+ // Paper end
if (navigationabstract != null && !navigationabstract.i()) {
PathEntity pathentity = navigationabstract.k();
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index cae2873..5ae2f14 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1024,6 +1024,7 @@ public abstract class World implements IBlockAccess {
this.getChunkAt(i, j).a(entity);
this.entityList.add(entity);
this.b(entity);
+ if (entity instanceof EntityInsentient) { this.getNavListener().add(((EntityInsentient) entity).navigation); } // Paper
return true;
}
}
@@ -1105,6 +1106,7 @@ public abstract class World implements IBlockAccess {
}
// CraftBukkit end
} // Spigot
+ if (entity instanceof EntityInsentient) { this.getNavListener().remove(((EntityInsentient) entity).navigation); } // Paper
this.c(entity);
}
--
2.7.2