Unnecessary array lookup

This commit is contained in:
themode 2022-03-25 08:23:33 +01:00
parent 9ee74845e1
commit 0fc9cab6ab

View File

@ -128,14 +128,14 @@ public class Tag<T> {
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);