diff --git a/patches/server/0103-Avoid-Class-isAssignableFrom-call-in-ClassInstanceMu.patch b/patches/server/0103-Avoid-Class-isAssignableFrom-call-in-ClassInstanceMu.patch new file mode 100644 index 00000000..7603f6e2 --- /dev/null +++ b/patches/server/0103-Avoid-Class-isAssignableFrom-call-in-ClassInstanceMu.patch @@ -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 extends AbstractCollection { + } + + public Collection find(Class 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 collection = this.byClass.get(type); ++ if (collection == null) { ++ collection = this.createAllOfType(type); + } ++ return (Collection) Collections.unmodifiableCollection(collection); ++ } ++ ++ private Collection createAllOfType(Class type) { ++ List 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