From 4f66fd793b99f173cea117c1bb22592c417aef17 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 25 Aug 2024 18:59:48 +0200 Subject: [PATCH] Go back to fast entity data list iteration and mutation This is a fairly hot method and the array list cannot be modified outside of the already managed event cancellation and provided extra list --- .../viaversion/rewriter/EntityRewriter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index eb18e8f80..74a3a4f73 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -110,7 +110,11 @@ public abstract class EntityRewriter dataList, final UserConnection connection) { final TrackedEntity entity = tracker(connection).entity(entityId); final EntityType type = entity != null ? entity.entityType() : null; - for (final EntityData entityData : dataList.toArray(EMPTY_ARRAY)) { // Copy the list to allow mutation + + // Iterate over indexed list to allow for removal and addition of elements, decrease current index and size if an element is removed + int size = dataList.size(); + for (int i = 0; i < size; i++) { + final EntityData entityData = dataList.get(i); EntityDataHandlerEvent event = null; for (final EntityDataFilter filter : entityDataFilters) { if (!filter.isFiltered(type, entityData)) { @@ -125,13 +129,15 @@ public abstract class EntityRewriter