Perf: memory optimizations

This commit is contained in:
yairm210
2024-04-25 14:15:01 +03:00
parent 3aa9be9e9e
commit b67b92de45
2 changed files with 8 additions and 2 deletions

View File

@ -415,9 +415,9 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
}
/** Returns the [civilizations][Civilization] that know about both sides ([civInfo] and [otherCiv]) */
fun getCommonKnownCivs(): Set<Civilization> = civInfo.getKnownCivs().toSet().intersect(otherCiv().getKnownCivs().toSet())
fun getCommonKnownCivs(): Set<Civilization> = civInfo.getKnownCivs().asIterable().intersect(otherCiv().getKnownCivs().toSet())
fun getCommonKnownCivsWithSpectators(): Set<Civilization> = civInfo.getKnownCivsWithSpectators().toSet().intersect(otherCiv().getKnownCivsWithSpectators().toSet())
fun getCommonKnownCivsWithSpectators(): Set<Civilization> = civInfo.getKnownCivsWithSpectators().asIterable().intersect(otherCiv().getKnownCivsWithSpectators().toSet())
/** Returns true when the [civInfo]'s territory is considered allied for [otherCiv].
* This includes friendly and allied city-states and the open border treaties.
*/

View File

@ -114,6 +114,11 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
if (! ::ruleset.isInitialized) { // Not sure if this will ever actually happen, but better safe than sorry
return ourUniques
}
val typeUniques = type.getMatchingUniques(uniqueType, stateForConditionals)
// Memory optimization - very rarely do we actually get uniques from both sources,
// and sequence addition is expensive relative to the rare case that we'll actually need it
if (ourUniques.none()) return typeUniques
if (typeUniques.none()) return ourUniques
return ourUniques + type.getMatchingUniques(uniqueType, stateForConditionals)
}
@ -423,6 +428,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
return false
}
fun isRanged() = rangedStrength > 0
fun isMelee() = !isRanged() && strength > 0
fun isMilitary() = isRanged() || isMelee()