9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 03:49:21 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0205-Make-removeIf-slightly-faster.patch
Dreeam 3c25377465 Drop some unused patches
ClassInstanceMultiMap belongs to Minecraft vanilla entity storage.
And is unused, since replaced by spottedleaf's entity storage (rewrite chunk system).
However these patches might be useful for vanilla entity storage if is used.
2025-07-09 04:20:02 +08:00

59 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 23 Feb 2025 00:37:39 +0100
Subject: [PATCH] Make removeIf slightly faster
diff --git a/net/minecraft/util/SortedArraySet.java b/net/minecraft/util/SortedArraySet.java
index e8bad6e1c0aeb67005661db6ed42f745554fa652..c2d64cdc5241d54379da2b843b6f28db8a8e39a9 100644
--- a/net/minecraft/util/SortedArraySet.java
+++ b/net/minecraft/util/SortedArraySet.java
@@ -19,36 +19,26 @@ public class SortedArraySet<T> extends AbstractSet<T> implements ca.spottedleaf.
// Paper start - rewrite chunk system
@Override
public final boolean removeIf(final java.util.function.Predicate<? super T> filter) {
- // prev. impl used an iterator, which could be n^2 and creates garbage
+ // Leaf start - Make removeIf slightly faster
int i = 0;
final int len = this.size;
final T[] backingArray = this.contents;
- for (;;) {
- if (i >= len) {
- return false;
- }
- if (!filter.test(backingArray[i++])) {
- continue;
- }
- break;
- }
+ // Find first element to remove
+ while (i < len && !filter.test(backingArray[i])) i++;
+ if (i == len) return false;
- // we only want to write back to backingArray if we really need to
-
- int lastIndex = i - 1; // this is where new elements are shifted to
-
- for (; i < len; ++i) {
- final T curr = backingArray[i];
- if (!filter.test(curr)) { // if test throws we're screwed
- backingArray[lastIndex++] = curr;
- }
+ // Shift elements in-place
+ int lastIndex = i;
+ for (i++; i < len; i++) {
+ T curr = backingArray[i];
+ if (!filter.test(curr)) backingArray[lastIndex++] = curr;
}
- // cleanup end
- Arrays.fill(backingArray, lastIndex, len, null);
+ // Only update size - skip Arrays.fill (safe in ChunkHolderManager's context)
this.size = lastIndex;
return true;
+ // Leaf end - Make removeIf slightly faster
}
@Override