Skip to content

Commit

Permalink
Use fastutils Set instead of Map to deduplicate quads
Browse files Browse the repository at this point in the history
  • Loading branch information
malte0811 committed Aug 10, 2023
1 parent abde468 commit 5087367
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package malte0811.ferritecore.impl;

import com.mojang.datafixers.util.Unit;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import it.unimi.dsi.fastutil.HashCommon;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import malte0811.ferritecore.hash.LambdaBasedHash;
import malte0811.ferritecore.mixin.dedupbakedquad.BakedQuadAccess;
import malte0811.ferritecore.util.PredicateHelper;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class Deduplicator {
private static final Map<List<Pair<Predicate<BlockState>, BakedModel>>, MultiPartBakedModel> KNOWN_MULTIPART_MODELS = new ConcurrentHashMap<>();
private static final Map<List<Predicate<BlockState>>, Predicate<BlockState>> OR_PREDICATE_CACHE = new ConcurrentHashMap<>();
private static final Map<List<Predicate<BlockState>>, Predicate<BlockState>> AND_PREDICATE_CACHE = new ConcurrentHashMap<>();
private static final Object2ObjectOpenCustomHashMap<int[], int[]> BAKED_QUAD_CACHE = new Object2ObjectOpenCustomHashMap<>(
private static final ObjectOpenCustomHashSet<int[]> BAKED_QUAD_CACHE = new ObjectOpenCustomHashSet<>(
new LambdaBasedHash<>(Arrays::hashCode, Arrays::equals)
);

Expand All @@ -52,7 +53,7 @@ public static Predicate<BlockState> and(List<Predicate<BlockState>> list) {

public static void deduplicate(BakedQuad bq) {
synchronized (BAKED_QUAD_CACHE) {
int[] deduped = BAKED_QUAD_CACHE.computeIfAbsent(bq.getVertices(), Function.identity());
int[] deduped = BAKED_QUAD_CACHE.addOrGet(bq.getVertices());
((BakedQuadAccess) bq).setVertices(deduped);
}
}
Expand Down

0 comments on commit 5087367

Please sign in to comment.