From 37438b60102f76f72f1587b01f933c35a24bedc0 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Sat, 22 Mar 2025 00:11:14 +0100 Subject: [PATCH] optimize ContextMap.create --- .../0152-Optimize-ContextMap.create.patch | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 leaf-server/minecraft-patches/features/0152-Optimize-ContextMap.create.patch diff --git a/leaf-server/minecraft-patches/features/0152-Optimize-ContextMap.create.patch b/leaf-server/minecraft-patches/features/0152-Optimize-ContextMap.create.patch new file mode 100644 index 00000000..6b6c68f9 --- /dev/null +++ b/leaf-server/minecraft-patches/features/0152-Optimize-ContextMap.create.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Taiyou06 +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> set = Sets.difference(this.params.keySet(), contextKeySet.allowed()); +- if (!set.isEmpty()) { +- throw new IllegalArgumentException("Parameters not allowed in this parameter set: " + set); +- } else { +- Set> 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> allowed = contextKeySet.allowed(); ++ Set> 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> required = contextKeySet.required(); ++ Set> 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); + } + } + }