mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-25 07:09:16 +07:00
Perf: memory optimizations
This commit is contained in:
@ -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.
|
||||
*/
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user