diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 43ce3c1bcc..2d27816ad6 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -63,7 +63,7 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization { var ruleset: Ruleset? = null @Transient - var tileUniqueMapCache = ConcurrentHashMap() + var tileUniqueMapCache = ConcurrentHashMap, UniqueMap>() @Transient var tileMatrix = ArrayList>() // this works several times faster than a hashmap, the performance difference is really astounding diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index d0a5ae617a..0a266e3bfd 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -844,14 +844,17 @@ open class Tile : IsPartOfGameInfoSerialization { private fun updateUniqueMap() { if (!::tileMap.isInitialized) return // This tile is a fake tile, for visual display only (e.g. map editor, civilopedia) - val terrainString = allTerrains.joinToString(";") { it.name } - val cachedUniqueMap = tileMap.tileUniqueMapCache[terrainString] - terrainUniqueMap = if (cachedUniqueMap != null) cachedUniqueMap + val terrainNameList = allTerrains.map { it.name }.toList() + + // List hash is function of all its items, so the same items in the same order will always give the same hash + val cachedUniqueMap = tileMap.tileUniqueMapCache[terrainNameList] + terrainUniqueMap = if (cachedUniqueMap != null) + cachedUniqueMap else { val newUniqueMap = UniqueMap() for (terrain in allTerrains) newUniqueMap.addUniques(terrain.uniqueObjects) - tileMap.tileUniqueMapCache[terrainString] = newUniqueMap + tileMap.tileUniqueMapCache[terrainNameList] = newUniqueMap newUniqueMap } }