From d75420a35bdb94ff2310ca1ed4e604b589494c91 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Mon, 7 Dec 2020 07:50:52 -0300 Subject: [PATCH] Use ArrayDeque, less ram for PacketWrapper.readableObjects (#2218) --- .../main/java/us/myles/ViaVersion/api/PacketWrapper.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 34689eaca..3012240c3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -15,8 +15,9 @@ import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.util.PipelineUtil; import java.io.IOException; +import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.LinkedList; +import java.util.Deque; import java.util.List; import java.util.NoSuchElementException; @@ -28,7 +29,7 @@ public class PacketWrapper { private final UserConnection userConnection; private boolean send = true; private int id = -1; - private final LinkedList> readableObjects = new LinkedList<>(); + private final Deque> readableObjects = new ArrayDeque<>(); private final List> packetValues = new ArrayList<>(); public PacketWrapper(int packetID, ByteBuf inputBuffer, UserConnection userConnection) { @@ -488,7 +489,9 @@ public class PacketWrapper { */ public void resetReader() { // Move all packet values to the readable for next packet. - this.readableObjects.addAll(0, packetValues); + for (int i = packetValues.size() - 1; i >= 0; i--) { + this.readableObjects.addFirst(this.packetValues.get(i)); + } this.packetValues.clear(); }