mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 01:49:16 +00:00
Use system arraycopy in blockEntity ticker list removing index & Update Leaf config util
supersedes https://github.com/Winds-Studio/Leaf/pull/380
This commit is contained in:
@@ -141,17 +141,41 @@ public class LeafGlobalConfig {
|
||||
|
||||
public Double getDouble(String path) {
|
||||
String value = configFile.getString(path, null);
|
||||
return value == null ? null : Double.parseDouble(value); // TODO: Need to check whether need to handle NFE correctly
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
} catch (NumberFormatException e) {
|
||||
LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getInt(String path) {
|
||||
String value = configFile.getString(path, null);
|
||||
return value == null ? null : Integer.parseInt(value); // TODO: Need to check whether need to handle NFE correctly
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Long getLong(String path) {
|
||||
String value = configFile.getString(path, null);
|
||||
return value == null ? null : Long.parseLong(value); // TODO: Need to check whether need to handle NFE correctly
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
} catch (NumberFormatException e) {
|
||||
LeafConfig.LOGGER.warn("{} is not a valid number, skipped! Please check your configuration.", path, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getList(String path) {
|
||||
|
||||
@@ -71,33 +71,35 @@ public final class BlockEntityTickersList extends ObjectArrayList<TickingBlockEn
|
||||
return; // exit early, we don't need to do anything
|
||||
|
||||
final Object[] a = this.a;
|
||||
int j = startSearchFromIndex;
|
||||
int writeIndex = startSearchFromIndex;
|
||||
int lastCopyIndex = startSearchFromIndex;
|
||||
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)) {
|
||||
// TODO: It can be possible to optimize this loop by tracking the start/finish and then using arraycopy to "skip" the elements,
|
||||
// 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
|
||||
// "arraycopy" for each element
|
||||
a[j++] = a[i];
|
||||
} else {
|
||||
matches++;
|
||||
}
|
||||
|
||||
if (matches == requiredMatches) { // Exit the loop if we already removed everything, we don't need to check anything else
|
||||
// We need to update the final size here, because we know that we already found everything!
|
||||
// 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 (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);
|
||||
for (int readIndex = startSearchFromIndex; readIndex < size; readIndex++) {
|
||||
if (c.contains(readIndex)) {
|
||||
matches++;
|
||||
final int blockLength = readIndex - lastCopyIndex;
|
||||
if (blockLength > 0) {
|
||||
System.arraycopy(a, lastCopyIndex, a, writeIndex, blockLength);
|
||||
writeIndex += blockLength;
|
||||
}
|
||||
lastCopyIndex = readIndex + 1;
|
||||
|
||||
if (matches == requiredMatches) {
|
||||
break;
|
||||
}
|
||||
j = size - requiredMatches;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Arrays.fill(a, j, size, null);
|
||||
size = j;
|
||||
final int finalBlockLength = size - lastCopyIndex;
|
||||
if (finalBlockLength > 0) {
|
||||
System.arraycopy(a, lastCopyIndex, a, writeIndex, finalBlockLength);
|
||||
writeIndex += finalBlockLength;
|
||||
}
|
||||
|
||||
if (writeIndex < size) {
|
||||
Arrays.fill(a, writeIndex, size, null);
|
||||
}
|
||||
size = writeIndex;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user