9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0141-Optimize-ContextMap.create.patch
2025-06-11 03:59:45 +08:00

62 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 22 Mar 2025 00:08:11 +0100
Subject: [PATCH] Optimize ContextMap.create
diff --git a/net/minecraft/util/context/ContextMap.java b/net/minecraft/util/context/ContextMap.java
index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..64a48913868d9b8c0a4bb3f97458a64c95e99034 100644
--- a/net/minecraft/util/context/ContextMap.java
+++ b/net/minecraft/util/context/ContextMap.java
@@ -72,17 +72,41 @@ public class ContextMap {
}
public ContextMap create(ContextKeySet contextKeySet) {
- Set<ContextKey<?>> set = Sets.difference(this.params.keySet(), contextKeySet.allowed());
- if (!set.isEmpty()) {
- throw new IllegalArgumentException("Parameters not allowed in this parameter set: " + set);
- } else {
- Set<ContextKey<?>> set1 = Sets.difference(contextKeySet.required(), this.params.keySet());
- if (!set1.isEmpty()) {
- throw new IllegalArgumentException("Missing required parameters: " + set1);
- } else {
- return new ContextMap(this.params);
+ // Leaf start - Optimize ContextMap.create
+ Set<ContextKey<?>> allowed = contextKeySet.allowed();
+ Set<ContextKey<?>> invalid = null;
+
+ // Check for any parameters that are not allowed
+ for (ContextKey<?> key : this.params.keySet()) {
+ if (!allowed.contains(key)) {
+ if (invalid == null) {
+ invalid = new java.util.HashSet<>();
+ }
+ invalid.add(key);
}
}
+ if (invalid != null) {
+ throw new IllegalArgumentException("Parameters not allowed in this parameter set: " + invalid);
+ }
+
+ Set<ContextKey<?>> required = contextKeySet.required();
+ Set<ContextKey<?>> missing = null;
+
+ // Check for any required parameters that are missing
+ for (ContextKey<?> reqKey : required) {
+ if (!this.params.containsKey(reqKey)) {
+ if (missing == null) {
+ missing = new java.util.HashSet<>();
+ }
+ missing.add(reqKey);
+ }
+ }
+ if (missing != null) {
+ throw new IllegalArgumentException("Missing required parameters: " + missing);
+ }
+
+ return new ContextMap(this.params);
+ // Leaf end - Optimize ContextMap.create
}
}
}