mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
61 lines
2.7 KiB
Diff
61 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Wed, 30 Nov 2022 21:15:33 +0100
|
|
Subject: [PATCH] Avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
|
|
|
Removed since 1.21.1, replaced by VMP optimization
|
|
|
|
License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
This patch is based on the following mixin:
|
|
"me/jellysquid/mods/lithium/mixin/collections/entity_filtering/TypeFilterableListMixin.java"
|
|
By: Angeline <jellysquid3@users.noreply.github.com>
|
|
As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
|
|
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
|
|
|
|
diff --git a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java b/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
|
index 4264b3a69b5cbe2e56058927ceb5409389cecf4b..1cdff53d2c39d785b3b3306eef27649a4b092e52 100644
|
|
--- a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
|
+++ b/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
|
@@ -56,13 +56,33 @@ public class ClassInstanceMultiMap<T> extends AbstractCollection<T> {
|
|
}
|
|
|
|
public <S> Collection<S> find(Class<S> type) {
|
|
- if (!this.baseClass.isAssignableFrom(type)) {
|
|
- throw new IllegalArgumentException("Don't know how to search for " + type);
|
|
- } else {
|
|
- List<? extends T> list = this.byClass
|
|
- .computeIfAbsent(type, typeClass -> this.allInstances.stream().filter(typeClass::isInstance).collect(Util.toMutableList()));
|
|
- return (Collection<S>)Collections.unmodifiableCollection(list);
|
|
+ // Gale start - Lithium - avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
|
+ /*
|
|
+ Only perform the slow Class#isAssignableFrom(Class) if a list doesn't exist for the type, otherwise
|
|
+ we can assume it's already valid. The slow-path code is moved to a separate method to help the JVM inline this.
|
|
+ */
|
|
+ Collection<T> collection = this.byClass.get(type);
|
|
+
|
|
+ if (collection == null) {
|
|
+ collection = this.createAllOfType(type);
|
|
}
|
|
+
|
|
+ return (Collection<S>) Collections.unmodifiableCollection(collection);
|
|
+ }
|
|
+
|
|
+ private <S> Collection<T> createAllOfType(Class<S> type) {
|
|
+ List<T> list = new java.util.ArrayList<>(1);
|
|
+
|
|
+ for (T allElement : this.allInstances) {
|
|
+ if (type.isInstance(allElement)) {
|
|
+ list.add(allElement);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ this.byClass.put(type, list);
|
|
+
|
|
+ return list;
|
|
+ // Gale end - Lithium - avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
|
}
|
|
|
|
@Override
|