From 0fc9cab6ab19de47d0a396efc275ecf75ceef18d Mon Sep 17 00:00:00 2001 From: themode Date: Fri, 25 Mar 2022 08:23:33 +0100 Subject: [PATCH] Unnecessary array lookup --- src/main/java/net/minestom/server/tag/Tag.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/minestom/server/tag/Tag.java b/src/main/java/net/minestom/server/tag/Tag.java index aea8d0b61..76c999fa7 100644 --- a/src/main/java/net/minestom/server/tag/Tag.java +++ b/src/main/java/net/minestom/server/tag/Tag.java @@ -128,14 +128,14 @@ public class Tag { return NBT.List(type, List.of(array)); }, null, path, copy != null ? ts -> { - T[] array = (T[]) new Object[ts.size()]; + final int size = ts.size(); + T[] array = (T[]) new Object[size]; boolean shallowCopy = true; - for (int i = 0; i < ts.size(); i++) { - T t = ts.get(i); - array[i] = copy.apply(t); - if (shallowCopy && array[i] != t) { - shallowCopy = false; - } + for (int i = 0; i < size; i++) { + final T t = ts.get(i); + final T copy = this.copy.apply(t); + if (shallowCopy && copy != t) shallowCopy = false; + array[i] = copy; } return shallowCopy ? List.copyOf(ts) : List.of(array); } : List::copyOf);