Files
MiraiMC/patches/server/0110-c2me-reduce_allocs.patch
2022-02-14 17:37:45 +01:00

53 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Mon, 24 Jan 2022 10:56:10 -0500
Subject: [PATCH] c2me: reduce_allocs
Copyright (c) 2021-2022 ishland
Original code by RelativityMC, licensed under MIT
You can find the original code on https://github.com/RelativityMC/C2ME-fabric (Yarn mappings)
diff --git a/src/main/java/com/ishland/c2me/common/optimization/reduce_allocs/ObjectCachingUtils.java b/src/main/java/com/ishland/c2me/common/optimization/reduce_allocs/ObjectCachingUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..9b9c3ed63421a48aa4ba341aef7042fc953147bb
--- /dev/null
+++ b/src/main/java/com/ishland/c2me/common/optimization/reduce_allocs/ObjectCachingUtils.java
@@ -0,0 +1,23 @@
+package com.ishland.c2me.common.optimization.reduce_allocs;
+
+import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
+
+import java.util.BitSet;
+import java.util.function.IntFunction;
+
+public class ObjectCachingUtils {
+
+ private static final IntFunction<BitSet> bitSetConstructor = BitSet::new;
+
+ public static ThreadLocal<Int2ObjectOpenHashMap<BitSet>> BITSETS = ThreadLocal.withInitial(Int2ObjectOpenHashMap::new);
+
+ private ObjectCachingUtils() {
+ }
+
+ public static BitSet getCachedOrNewBitSet(int bits) {
+ final BitSet bitSet = BITSETS.get().computeIfAbsent(bits, bitSetConstructor);
+ bitSet.clear();
+ return bitSet;
+ }
+
+}
diff --git a/src/main/java/net/minecraft/world/level/levelgen/feature/OreFeature.java b/src/main/java/net/minecraft/world/level/levelgen/feature/OreFeature.java
index 4f3bfac8b387297df25d56ef957d10f30a257872..5a96e7215912b17dc780bb68eee1acd63a86381b 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/feature/OreFeature.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/feature/OreFeature.java
@@ -54,7 +54,7 @@ public class OreFeature extends Feature<OreConfiguration> {
protected boolean doPlace(WorldGenLevel world, Random random, OreConfiguration config, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int horizontalSize, int verticalSize) {
int i = 0;
- BitSet bitSet = new BitSet(horizontalSize * verticalSize * horizontalSize);
+ BitSet bitSet = com.ishland.c2me.common.optimization.reduce_allocs.ObjectCachingUtils.getCachedOrNewBitSet(horizontalSize * verticalSize * horizontalSize); // JettPack - C2ME: reduce_allocs
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
int j = config.size;
double[] ds = new double[j * 4];