aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch
diff options
context:
space:
mode:
authorJake Potrebic <[email protected]>2021-12-22 10:02:31 -0800
committerGitHub <[email protected]>2021-12-22 10:02:31 -0800
commit82eaf4ee15d77303cdd352cce9b33c2f3e5d14d7 (patch)
tree53e4a42978675fc17acc76b85dcb0c3569ab3e3b /patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch
parent6e5ceb34eb2ef4d6c0a35c46d0eded9099bb2fee (diff)
downloadPaper-82eaf4ee15d77303cdd352cce9b33c2f3e5d14d7.tar.gz
Paper-82eaf4ee15d77303cdd352cce9b33c2f3e5d14d7.zip
Fix duplicated BlockPistonRetractEvent call (#7111)
Diffstat (limited to 'patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch')
-rw-r--r--patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch54
1 files changed, 54 insertions, 0 deletions
diff --git a/patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch b/patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch
new file mode 100644
index 0000000000..f60ffe8b92
--- /dev/null
+++ b/patches/server/0474-Optimize-the-advancement-data-player-iteration-to-be.patch
@@ -0,0 +1,54 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Wyatt Childers <[email protected]>
+Date: Sat, 4 Jul 2020 23:07:43 -0400
+Subject: [PATCH] Optimize the advancement data player iteration to be O(N)
+ rather than O(N^2)
+
+
+diff --git a/src/main/java/net/minecraft/server/PlayerAdvancements.java b/src/main/java/net/minecraft/server/PlayerAdvancements.java
+index 3d82f984648605d58fae3c57f145d0da8a2ae225..bd858a9da2f2442be85f36bb2de0dac46d0c68d7 100644
+--- a/src/main/java/net/minecraft/server/PlayerAdvancements.java
++++ b/src/main/java/net/minecraft/server/PlayerAdvancements.java
+@@ -437,6 +437,16 @@ public class PlayerAdvancements {
+ }
+
+ private void ensureVisibility(Advancement advancement) {
++ // Paper start
++ ensureVisibility(advancement, IterationEntryPoint.ROOT);
++ }
++ private enum IterationEntryPoint {
++ ROOT,
++ ITERATOR,
++ PARENT_OF_ITERATOR
++ }
++ private void ensureVisibility(Advancement advancement, IterationEntryPoint entryPoint) {
++ // Paper end
+ boolean flag = this.shouldBeVisible(advancement);
+ boolean flag1 = this.visible.contains(advancement);
+
+@@ -452,15 +462,23 @@ public class PlayerAdvancements {
+ }
+
+ if (flag != flag1 && advancement.getParent() != null) {
+- this.ensureVisibility(advancement.getParent());
++ // Paper start - If we're not coming from an iterator consider this to be a root entry, otherwise
++ // market that we're entering from the parent of an iterator.
++ this.ensureVisibility(advancement.getParent(), entryPoint == IterationEntryPoint.ITERATOR ? IterationEntryPoint.PARENT_OF_ITERATOR : IterationEntryPoint.ROOT);
+ }
+
++ // If this is true, we've went through a child iteration, entered the parent, processed the parent
++ // and are about to reprocess the children. Stop processing here to prevent O(N^2) processing.
++ if (entryPoint == IterationEntryPoint.PARENT_OF_ITERATOR) {
++ return;
++ } // Paper end
++
+ Iterator iterator = advancement.getChildren().iterator();
+
+ while (iterator.hasNext()) {
+ Advancement advancement1 = (Advancement) iterator.next();
+
+- this.ensureVisibility(advancement1);
++ this.ensureVisibility(advancement1, IterationEntryPoint.ITERATOR); // Paper - Mark this call as being from iteration
+ }
+
+ }