Paper/Spigot-Server-Patches/0079-Optimize-NavigationListener-Iteration.patch
Aikar d2f5881fa4 Optimize NavigationListener Iteration
I don't know what the person who wrote that code was smoking, but I
don't think it was good.
2016-03-07 22:59:12 -05:00

55 lines
2.4 KiB
Diff

From 2b83ee072b998c629fa5b0f0649faf5e28218b90 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.
diff --git a/src/main/java/net/minecraft/server/NavigationListener.java b/src/main/java/net/minecraft/server/NavigationListener.java
index f82ea80..b4f1fdc 100644
--- a/src/main/java/net/minecraft/server/NavigationListener.java
+++ b/src/main/java/net/minecraft/server/NavigationListener.java
@@ -1,26 +1,32 @@
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> b = new ArrayList<>(); // Paper
public NavigationListener() {}
public void a(NavigationAbstract navigationabstract) {
- this.b.put(navigationabstract, NavigationListener.a);
+ org.spigotmc.AsyncCatcher.catchOp("Async Navigation Add"); // Paper
+ this.b.add(navigationabstract); // Paper
}
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.b.keySet().toArray(new NavigationAbstract[0]);
+ //NavigationAbstract[] anavigationabstract1 = anavigationabstract;
+ int j = this.b.size();
+
for (int k = 0; k < j; ++k) {
- NavigationAbstract navigationabstract = anavigationabstract1[k];
+ NavigationAbstract navigationabstract = this.b.get(k);
+ // Paper end
if (navigationabstract != null && !navigationabstract.i()) {
PathEntity pathentity = navigationabstract.k();
--
2.7.2