From c487a64ba8eeeac42262bd4c7e9512a18e3c0a5d Mon Sep 17 00:00:00 2001 From: yairm210 Date: Mon, 16 Sep 2024 04:29:55 +0300 Subject: [PATCH] Reapply "perf: minor speedup in distance to tiles" This reverts commit 14115cdea7bd3b4902179de71a1b096d7175ebdb. --- core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt index 8ef6d550f7..86f6b7e88c 100644 --- a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt @@ -70,7 +70,8 @@ class UnitMovement(val unit: MapUnit) { } } - if (!distanceToTiles.containsKey(neighbor) || distanceToTiles[neighbor]!!.totalDistance > totalDistanceToTile) { // this is the new best path + val currentBestPath = distanceToTiles[neighbor] + if (currentBestPath == null || currentBestPath.totalDistance > totalDistanceToTile) { // this is the new best path val usableMovement = if (includeOtherEscortUnit && unit.isEscorting()) minOf(unitMovement, unit.getOtherEscortUnit()!!.currentMovement) else unitMovement