mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-15 07:05:44 +01:00
ce270e1412
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: b2f1908c SPIGOT-5783: Add helpful info to UnknownDependencyException e4f46260 SPIGOT-2623: Add EntityEquipment methods to get/set ItemStacks by slot. 529a9a69 SPIGOT-5751: Clarify behaviour of block drop-related API methods CraftBukkit Changes:8ea9b138
Remove outdated build delay.ffc2b251
Revert "#675: Fix redirected CommandNodes sometimes not being properly redirected"cb701f6b
#675: Fix redirected CommandNodes sometimes not being properly redirectedc9d7c16b
SPIGOT-2623: Add EntityEquipment methods to get/set ItemStacks by slot.fad2494a
#673: Fix Craftworld#isChunkLoaded8637ec00
SPIGOT-5751: Made breakNaturally and getDrops returns the correct item if no argument is given Spigot Changes: a99063f7 Rebuild patches Fixes #3602
66 lines
2.5 KiB
Diff
66 lines
2.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Wed, 15 Apr 2020 18:23:28 -0700
|
|
Subject: [PATCH] Optimise ArraySetSorted#removeIf
|
|
|
|
Remove iterator allocation and ensure the call is always O(n)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ArraySetSorted.java b/src/main/java/net/minecraft/server/ArraySetSorted.java
|
|
index 85f799a713db0c822d46b689010f9f6bd43f5280..7db6b5850b91588eb4d91f0d7e8b5dbbcb95b7cb 100644
|
|
--- a/src/main/java/net/minecraft/server/ArraySetSorted.java
|
|
+++ b/src/main/java/net/minecraft/server/ArraySetSorted.java
|
|
@@ -10,8 +10,8 @@ import java.util.NoSuchElementException;
|
|
public class ArraySetSorted<T> extends AbstractSet<T> {
|
|
|
|
private final Comparator<T> a;
|
|
- private T[] b;
|
|
- private int c;
|
|
+ private T[] b; private final T[] getBackingArray() { return this.b; } // Paper - OBFHELPER
|
|
+ private int c; private final int getSize() { return this.c; } private final void setSize(int value) { this.c = value; } // Paper - OBFHELPER
|
|
|
|
private ArraySetSorted(int i, Comparator<T> comparator) {
|
|
this.a = comparator;
|
|
@@ -22,6 +22,42 @@ public class ArraySetSorted<T> extends AbstractSet<T> {
|
|
}
|
|
}
|
|
|
|
+ // Paper start - optimise removeIf
|
|
+ @Override
|
|
+ public boolean removeIf(java.util.function.Predicate<? super T> filter) {
|
|
+ // prev. impl used an iterator, which could be n^2 and creates garbage
|
|
+ int i = 0, len = this.getSize();
|
|
+ T[] backingArray = this.getBackingArray();
|
|
+
|
|
+ for (;;) {
|
|
+ if (i >= len) {
|
|
+ return false;
|
|
+ }
|
|
+ if (!filter.test(backingArray[i])) {
|
|
+ ++i;
|
|
+ continue;
|
|
+ }
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ // we only want to write back to backingArray if we really need to
|
|
+
|
|
+ int lastIndex = i; // this is where new elements are shifted to
|
|
+
|
|
+ for (; i < len; ++i) {
|
|
+ T curr = backingArray[i];
|
|
+ if (!filter.test(curr)) { // if test throws we're screwed
|
|
+ backingArray[lastIndex++] = curr;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // cleanup end
|
|
+ Arrays.fill(backingArray, lastIndex, len, null);
|
|
+ this.setSize(lastIndex);
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end - optimise removeIf
|
|
+
|
|
public static <T extends Comparable<T>> ArraySetSorted<T> a(int i) {
|
|
return new ArraySetSorted<>(i, (Comparator)Comparator.naturalOrder()); // Paper - decompile fix
|
|
}
|