9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

additional opts to BlockEntityTickersList

This commit is contained in:
NONPLAYT
2025-06-28 23:32:18 +03:00
parent 72af777b2a
commit 9feb5e9577

View File

@@ -67,32 +67,35 @@ public final class BlockEntityTickersList extends ObjectArrayList<TickingBlockEn
return; // exit early, we don't need to do anything return; // exit early, we don't need to do anything
final Object[] a = this.a; final Object[] a = this.a;
int j = startSearchFromIndex; int destPos = startSearchFromIndex;
int copyStart = startSearchFromIndex;
int matches = 0; int matches = 0;
for (int i = startSearchFromIndex; i < size; i++) { // If the user knows the first index to be removed, we can skip a lot of unnecessary comparsions
if (!c.contains(i)) { for (int i = startSearchFromIndex; i < size; i++) {
// TODO: It can be possible to optimize this loop by tracking the start/finish and then using arraycopy to "skip" the elements, if (c.contains(i)) {
// this would optimize cases where the index to be removed are far apart, HOWEVER it does have a big performance impact if you are doing int copyLength = i - copyStart;
// "arraycopy" for each element if (copyLength > 0) {
a[j++] = a[i]; System.arraycopy(a, copyStart, a, destPos, copyLength);
} else { destPos += copyLength;
matches++;
} }
if (matches == requiredMatches) { // Exit the loop if we already removed everything, we don't need to check anything else copyStart = i + 1;
// We need to update the final size here, because we know that we already found everything! matches++;
// Because we know that the size must be currentSize - requiredMatches (because we have matched everything), let's update the value
// However, we need to copy the rest of the stuff over if (matches == requiredMatches) {
if (i != (size - 1)) { // If it isn't the last index...
// i + 1 because we want to copy the *next* element over
// and the size - i - 1 is because we want to get the current size, minus the current index (which is i), and then - 1 because we want to copy -1 ahead (remember, we are adding +1 to copy the *next* element)
System.arraycopy(a, i + 1, a, j, size - i - 1);
}
j = size - requiredMatches;
break; break;
} }
} }
Arrays.fill(a, j, size, null); }
size = j;
int remainingLength = size - copyStart;
if (remainingLength > 0) {
System.arraycopy(a, copyStart, a, destPos, remainingLength);
destPos += remainingLength;
}
// Clear remaining references and update size
if (destPos < size) Arrays.fill(a, destPos, size, null);
size = destPos;
} }
} }