mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-21 07:49:35 +00:00
Update 1.20.2 (#139)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
||||
Date: Thu, 20 Jul 2023 17:23:33 +0800
|
||||
Subject: [PATCH] Avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
||||
|
||||
This patch is Powered by Gale(https://github.com/GaleMC/Gale)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java b/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
||||
index 53021c7d173b3c067322e356fead0949aac3fc60..820343861893a0aba55ede10ac2a2594de4438d0 100644
|
||||
--- a/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
||||
+++ b/src/main/java/net/minecraft/util/ClassInstanceMultiMap.java
|
||||
@@ -55,14 +55,24 @@ 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 list = this.byClass.computeIfAbsent(type, (typeClass) -> { // Leaves - dev fix
|
||||
- return this.allInstances.stream().filter(typeClass::isInstance).collect(Collectors.toList());
|
||||
- });
|
||||
- return Collections.unmodifiableCollection(list);
|
||||
+ // Leaves start - avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
||||
+ 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;
|
||||
+ // Leaves end - avoid Class#isAssignableFrom call in ClassInstanceMultiMap
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user