9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-04 15:41:40 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0245-Use-HashedList-on-WeightedList.patch
Dreeam 9a4efaa230 Drop patch that causes performance regression
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2
since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList.
Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2
lazy handles filter condition on iteration, so much better.
2025-08-04 19:25:56 +08:00

36 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Tue, 13 May 2025 20:41:07 +0200
Subject: [PATCH] Use HashedList on WeightedList
diff --git a/net/minecraft/util/random/WeightedList.java b/net/minecraft/util/random/WeightedList.java
index daab145028c59c07049a2cf75c4f159e4c5073dc..4bb07ffde3674dc8d09b858ec0bd1ebc8a83bff1 100644
--- a/net/minecraft/util/random/WeightedList.java
+++ b/net/minecraft/util/random/WeightedList.java
@@ -19,6 +19,7 @@ public class WeightedList<E> { // Paper - non-final
private final List<Weighted<E>> items;
@Nullable
private final WeightedList.Selector<E> selector;
+ private List<Weighted<E>> entryHashList; // Leaf - Use HashedList on WeightedList
protected WeightedList(List<? extends Weighted<E>> items) { // Paper - protected
this.items = List.copyOf(items);
@@ -30,6 +31,7 @@ public class WeightedList<E> { // Paper - non-final
} else {
this.selector = new WeightedList.Compact<>(this.items);
}
+ this.entryHashList = this.items.size() > 4 ? this.items : java.util.Collections.unmodifiableList(new org.dreeam.leaf.util.list.HashedReferenceList<>(this.items)); // Leaf - Use HashedList on WeightedList
}
public static <E> WeightedList<E> of() {
@@ -80,7 +82,7 @@ public class WeightedList<E> { // Paper - non-final
}
public List<Weighted<E>> unwrap() {
- return this.items;
+ return this.entryHashList; // Leaf - Use HashedList on WeightedList
}
public static <E> Codec<WeightedList<E>> codec(Codec<E> elementCodec) {