node map performance, fixes #107

This commit is contained in:
Leijurv
2018-08-29 13:21:54 -07:00
parent 5c5507cc9e
commit cebdd76ca7
2 changed files with 17 additions and 11 deletions

View File

@@ -20,10 +20,9 @@ package baritone.pathing.calc;
import baritone.pathing.goals.Goal;
import baritone.pathing.path.IPath;
import baritone.utils.pathing.BetterBlockPos;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.util.math.BlockPos;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
@@ -42,7 +41,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
protected final Goal goal;
protected final Map<BetterBlockPos, PathNode> map;
private final Long2ObjectOpenHashMap<PathNode> map; // see issue #107
protected PathNode startNode;
@@ -69,7 +68,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
AbstractNodeCostSearch(BlockPos start, Goal goal) {
this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ());
this.goal = goal;
this.map = new HashMap<>();
this.map = new Long2ObjectOpenHashMap<>();
}
public void cancel() {
@@ -112,7 +111,14 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
* @return The associated node
*/
protected PathNode getNodeAtPosition(BetterBlockPos pos) {
return map.computeIfAbsent(pos, p -> new PathNode(p, goal));
// see issue #107
long hashCode = pos.hashCode;
PathNode node = map.get(hashCode);
if (node == null) {
node = new PathNode(pos, goal);
map.put(hashCode, node);
}
return node;
}
@Override