perf: 'getWorkingCity' optimization

This commit is contained in:
yairm210 2024-11-04 14:58:43 +02:00
parent 34c3abe74b
commit 82481162c8

View File

@ -390,7 +390,8 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
fun getWorkingCity(): City? { fun getWorkingCity(): City? {
val civInfo = getOwner() ?: return null val civInfo = getOwner() ?: return null
return civInfo.cities.firstOrNull { it.isWorked(this) } if (owningCity?.isWorked(this) == true) return owningCity // common case
return civInfo.cities.firstOrNull { it != owningCity && it.isWorked(this) }
} }
fun isBlockaded(): Boolean { fun isBlockaded(): Boolean {
@ -422,7 +423,8 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
fun isWorked(): Boolean = getWorkingCity() != null fun isWorked(): Boolean = getWorkingCity() != null
fun providesYield(): Boolean { fun providesYield(): Boolean {
if (getCity() == null) return false if (getCity() == null) return false
return isCityCenter() || isWorked() return isCityCenter()
|| isWorked()
|| getUnpillagedTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation) == true || getUnpillagedTileImprovement()?.hasUnique(UniqueType.TileProvidesYieldWithoutPopulation) == true
|| terrainHasUnique(UniqueType.TileProvidesYieldWithoutPopulation) || terrainHasUnique(UniqueType.TileProvidesYieldWithoutPopulation)
} }