From b0bf22e6d149ac4a39dc7ab67d50e97ac098d66a Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 17 Dec 2024 14:07:13 +0200 Subject: [PATCH] perf (ANR): Only parse and sort civs in global politics table once --- .../overviewscreen/GlobalPoliticsOverviewTable.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt b/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt index f8f1a1d46d..c42fc72a8a 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/GlobalPoliticsOverviewTable.kt @@ -66,8 +66,8 @@ class GlobalPoliticsOverviewTable( } // Reusable sequences for the Civilizations to display - private var undefeatedCivs = sequenceOf() - private var defeatedCivs = sequenceOf() + private var undefeatedCivs = listOf() + private var defeatedCivs = listOf() private var relevantCivsCount = "?" // includes unknown civs if player allowed to know private var showDiplomacyGroup = false @@ -292,10 +292,10 @@ class GlobalPoliticsOverviewTable( else gameInfo.civilizations.count { !it.isSpectator() && !it.isBarbarian && (persistableData.includeCityStates || !it.isCityState) }.tr() - undefeatedCivs = sequenceOf(viewingPlayer) + + undefeatedCivs = listOf(viewingPlayer) + viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates) defeatedCivs = viewingPlayer.diplomacyFunctions.getKnownCivsSorted(persistableData.includeCityStates, true) - .filter { it.isDefeated() } + .filter { it.isDefeated() }.toList() clear() fixedContent.clear() @@ -373,7 +373,7 @@ class GlobalPoliticsOverviewTable( add("Turns until the next\ndiplomacy victory vote: [$turnsTillNextDiplomaticVote]".toLabel()).colspan(columns).row() } - private fun Table.addCivsCategory(columns: Int, aliveOrDefeated: String, civs: Sequence) { + private fun Table.addCivsCategory(columns: Int, aliveOrDefeated: String, civs: List) { addSeparator() val count = civs.count() add("Known and $aliveOrDefeated ([$count])".toLabel()) @@ -410,7 +410,7 @@ class GlobalPoliticsOverviewTable( * @param freeSize Width and height this [Group] sizes itself to */ private class DiplomacyGroup( - undefeatedCivs: Sequence, + undefeatedCivs: List, freeSize: Float ): Group() { private fun onCivClicked(civLines: HashMap>, name: String) {