From 4591fd7eb36f7a548c51955fa38ca18f85f819e8 Mon Sep 17 00:00:00 2001 From: Brady Date: Sat, 1 Jul 2023 17:16:51 -0500 Subject: [PATCH] Use `Reference2DoubleOpenHashMap` in `ToolSet` --- src/main/java/baritone/utils/ToolSet.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index e9b9043bb..d28d949db 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -20,6 +20,7 @@ package baritone.utils; import baritone.Baritone; import baritone.PerformanceCritical; import baritone.utils.accessor.IItemTool; +import it.unimi.dsi.fastutil.objects.Reference2DoubleOpenHashMap; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; @@ -30,8 +31,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; -import java.util.HashMap; -import java.util.Map; import java.util.function.Function; /** @@ -45,7 +44,7 @@ public class ToolSet { * A cache mapping a {@link Block} to how long it will take to break * with this toolset, given the optimum tool is used. */ - private final Map breakStrengthCache; + private final Reference2DoubleOpenHashMap breakStrengthCache; /** * My buddy leijurv owned me so we have this to not create a new lambda instance. @@ -55,15 +54,15 @@ public class ToolSet { private final EntityPlayerSP player; public ToolSet(EntityPlayerSP player) { - breakStrengthCache = new HashMap<>(); + this.breakStrengthCache = new Reference2DoubleOpenHashMap<>(); this.player = player; if (Baritone.settings().considerPotionEffects.value) { double amplifier = potionAmplifier(); Function amplify = x -> amplifier * x; - backendCalculation = amplify.compose(this::getBestDestructionTime); + this.backendCalculation = amplify.compose(this::getBestDestructionTime); } else { - backendCalculation = this::getBestDestructionTime; + this.backendCalculation = this::getBestDestructionTime; } } @@ -75,7 +74,9 @@ public class ToolSet { */ @PerformanceCritical public double getStrVsBlock(IBlockState state) { - return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation); + // fastutil 8+ has a computeIfAbsent overload that uses a primitive mapping function + // for now, we're stuck with the boxed implementation + return this.breakStrengthCache.computeIfAbsent(state.getBlock(), this.backendCalculation); } /**