Do not create unneccessary callback in ChunkTaskScheduler#scheduleChunkLoad

If the parameter has addTicket = false and onComplete = null,
then the loadCallback would do no work and as a result does
not need to be created.
This commit is contained in:
Spottedleaf 2024-11-18 22:47:09 -08:00
parent 8c5b837e05
commit 37b9630f6a

View file

@ -8246,10 +8246,10 @@ index 0000000000000000000000000000000000000000..91a6f57f35fc1553159cca138a0619e7
+} +}
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..877e48375ac987169011051108c6c5102f8c0590 index 0000000000000000000000000000000000000000..b0bfe655922877676948d9b6ff3fa5a6ebb7a640
--- /dev/null --- /dev/null
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkTaskScheduler.java
@@ -0,0 +1,1036 @@ @@ -0,0 +1,1038 @@
+package ca.spottedleaf.moonrise.patches.chunk_system.scheduling; +package ca.spottedleaf.moonrise.patches.chunk_system.scheduling;
+ +
+import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor; +import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor;
@ -8831,7 +8831,7 @@ index 0000000000000000000000000000000000000000..877e48375ac987169011051108c6c510
+ this.chunkHolderManager.processTicketUpdates(); + this.chunkHolderManager.processTicketUpdates();
+ } + }
+ +
+ final Consumer<ChunkAccess> loadCallback = (final ChunkAccess chunk) -> { + final Consumer<ChunkAccess> loadCallback = onComplete == null && !addTicket ? null : (final ChunkAccess chunk) -> {
+ try { + try {
+ if (onComplete != null) { + if (onComplete != null) {
+ onComplete.accept(chunk); + onComplete.accept(chunk);
@ -8868,9 +8868,11 @@ index 0000000000000000000000000000000000000000..877e48375ac987169011051108c6c510
+ if (!chunkHolder.upgradeGenTarget(toStatus)) { + if (!chunkHolder.upgradeGenTarget(toStatus)) {
+ this.schedule(chunkX, chunkZ, toStatus, chunkHolder, tasks); + this.schedule(chunkX, chunkZ, toStatus, chunkHolder, tasks);
+ } + }
+ if (loadCallback != null) {
+ chunkHolder.addStatusConsumer(toStatus, loadCallback); + chunkHolder.addStatusConsumer(toStatus, loadCallback);
+ } + }
+ } + }
+ }
+ } finally { + } finally {
+ this.schedulingLockArea.unlock(schedulingLock); + this.schedulingLockArea.unlock(schedulingLock);
+ } + }
@ -8882,7 +8884,7 @@ index 0000000000000000000000000000000000000000..877e48375ac987169011051108c6c510
+ tasks.get(i).schedule(); + tasks.get(i).schedule();
+ } + }
+ +
+ if (!scheduled) { + if (loadCallback != null && !scheduled) {
+ // couldn't schedule + // couldn't schedule
+ try { + try {
+ loadCallback.accept(chunk); + loadCallback.accept(chunk);