-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid Class#isAssignableFrom call in ClassInstanceMultiMap
- Loading branch information
1 parent
d166b82
commit f294e38
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
patches/server/0103-Avoid-Class-isAssignableFrom-call-in-ClassInstanceMu.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |