From 669429b5aee9103951c2c3163b42193b8c7239b1 Mon Sep 17 00:00:00 2001 From: Alfie Cleveland Date: Fri, 25 Nov 2016 13:22:40 +0000 Subject: [PATCH] Optimise removeQueue diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 3c67a03a9..d5344d5c8 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -4,7 +4,9 @@ import com.google.common.collect.Lists; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Either; import io.netty.util.concurrent.Future; +import java.util.ArrayDeque; // Paper import java.util.Collection; +import java.util.Deque; // Paper import java.util.Iterator; import java.util.List; import java.util.OptionalInt; @@ -41,7 +43,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public PlayerConnection playerConnection; public final MinecraftServer server; public final PlayerInteractManager playerInteractManager; - public final List removeQueue = Lists.newLinkedList(); + public final Deque removeQueue = new ArrayDeque<>(); // Paper private final AdvancementDataPlayer advancementDataPlayer; private final ServerStatisticManager serverStatisticManager; private float lastHealthScored = Float.MIN_VALUE; @@ -367,13 +369,20 @@ public class EntityPlayer extends EntityHuman implements ICrafting { while (!this.removeQueue.isEmpty()) { int i = Math.min(this.removeQueue.size(), Integer.MAX_VALUE); int[] aint = new int[i]; - Iterator iterator = this.removeQueue.iterator(); + //Iterator iterator = this.removeQueue.iterator(); // Paper int j = 0; - while (iterator.hasNext() && j < i) { + // Paper start + /* while (iterator.hasNext() && j < i) { aint[j++] = (Integer) iterator.next(); iterator.remove(); + } */ + + Integer integer; + while (j < i && (integer = this.removeQueue.poll()) != null) { + aint[j++] = integer.intValue(); } + // Paper end this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(aint)); } @@ -1323,7 +1332,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.lastHealthSent = -1.0F; this.lastFoodSent = -1; // this.recipeBook.a((RecipeBook) entityplayer.recipeBook); // CraftBukkit - this.removeQueue.addAll(entityplayer.removeQueue); + // Paper start - Optimize remove queue - vanilla copies player objects, but CB doesn't. This method currently only + // Applies to the same player, so we need to not duplicate our removal queue. The rest of this method does "resetting" + // type logic so it does need to be called, maybe? This is silly. + //this.removeQueue.addAll(entityplayer.removeQueue); + if (this.removeQueue != entityplayer.removeQueue) { + this.removeQueue.addAll(entityplayer.removeQueue); + } + // Paper end this.cp = entityplayer.cp; this.cu = entityplayer.cu; this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft()); -- 2.22.0