9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0133-Replace-IdMapper-id-map-with-optimized-collection.patch
2025-03-07 15:49:01 -05:00

44 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Mon, 24 Feb 2025 16:33:46 +0100
Subject: [PATCH] Replace IdMapper id map with optimized collection
diff --git a/net/minecraft/core/IdMapper.java b/net/minecraft/core/IdMapper.java
index 439dc29b8ee8a1dc2ec63c00a9727a37bb697bad..be80e0bd9b44f7a04075827f0a8f22a126031c07 100644
--- a/net/minecraft/core/IdMapper.java
+++ b/net/minecraft/core/IdMapper.java
@@ -11,7 +11,7 @@ import javax.annotation.Nullable;
public class IdMapper<T> implements IdMap<T> {
private int nextId;
- private final Reference2IntMap<T> tToId;
+ private final it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap<T> tToId; // Leaf - Optimize IdMapper
private final List<T> idToT;
public IdMapper() {
@@ -20,7 +20,22 @@ public class IdMapper<T> implements IdMap<T> {
public IdMapper(int expectedSize) {
this.idToT = Lists.newArrayListWithExpectedSize(expectedSize);
- this.tToId = new Reference2IntOpenHashMap<>(expectedSize);
+ // Leaf start - Replace IdMapper id map with optimized collection
+ this.tToId = new it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap<>(
+ expectedSize,
+ new it.unimi.dsi.fastutil.Hash.Strategy<>() {
+ @Override
+ public int hashCode(T o) {
+ return System.identityHashCode(o);
+ }
+
+ @Override
+ public boolean equals(T a, T b) {
+ return a == b;
+ }
+ }
+ );
+ // Leaf end - Replace IdMapper id map with optimized collection
this.tToId.defaultReturnValue(-1);
}