9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 10:29:13 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0149-Optimize-ContextMap.create.patch
2025-03-25 03:29:15 -04:00

73 lines
2.8 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..9b1152db265afd87f17f0b7d4b2d09f4913b2f9c 100644
--- a/net/minecraft/util/context/ContextMap.java
+++ b/net/minecraft/util/context/ContextMap.java
@@ -1,10 +1,8 @@
package net.minecraft.util.context;
import com.google.common.collect.Sets;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+
+import java.util.*;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Contract;
@@ -72,17 +70,39 @@ 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);
+ 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 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 HashSet<>();
+ }
+ missing.add(reqKey);
}
}
+ if (missing != null) {
+ throw new IllegalArgumentException("Missing required parameters: " + missing);
+ }
+
+ return new ContextMap(this.params);
}
}
}