Optimize BlockState/Biome Wrapper getter methods

The lambdas were being newly created for each get() which became difficult for the GC to handle.
This commit is contained in:
James Seibel
2023-09-10 19:35:37 -05:00
parent ef6fc07cd3
commit 2107d3cbbd
2 changed files with 24 additions and 4 deletions
@@ -66,9 +66,9 @@ public class BiomeWrapper implements IBiomeWrapper
private static final Logger LOGGER = LogManager.getLogger();
#if PRE_MC_1_18_2
public static final ConcurrentMap<Biome, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
public static final ConcurrentMap<Biome, BiomeWrapper> WRAPPER_BY_BIOME = new ConcurrentHashMap<>();
#else
public static final ConcurrentMap<Holder<Biome>, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
public static final ConcurrentMap<Holder<Biome>, BiomeWrapper> WRAPPER_BY_BIOME = new ConcurrentHashMap<>();
#endif
public static final String EMPTY_STRING = "EMPTY";
@@ -100,7 +100,17 @@ public class BiomeWrapper implements IBiomeWrapper
return EMPTY_WRAPPER;
}
return biomeWrapperMap.computeIfAbsent(biome, newBiome -> new BiomeWrapper(newBiome, levelWrapper));
if (WRAPPER_BY_BIOME.containsKey(biome))
{
return WRAPPER_BY_BIOME.get(biome);
}
else
{
BiomeWrapper newWrapper = new BiomeWrapper(biome, levelWrapper);
WRAPPER_BY_BIOME.put(biome, newWrapper);
return newWrapper;
}
}
private BiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome, ILevelWrapper levelWrapper)
@@ -91,7 +91,17 @@ public class BlockStateWrapper implements IBlockStateWrapper
return AIR;
}
return WRAPPER_BY_BLOCK_STATE.computeIfAbsent(blockState, newBlockState -> new BlockStateWrapper(newBlockState, levelWrapper));
if (WRAPPER_BY_BLOCK_STATE.containsKey(blockState))
{
return WRAPPER_BY_BLOCK_STATE.get(blockState);
}
else
{
BlockStateWrapper newWrapper = new BlockStateWrapper(blockState, levelWrapper);
WRAPPER_BY_BLOCK_STATE.put(blockState, newWrapper);
return newWrapper;
}
}
private BlockStateWrapper(BlockState blockState, ILevelWrapper levelWrapper)