More sequencing for faster unique filtering

This commit is contained in:
Yair Morgenstern 2021-07-19 23:13:36 +03:00
parent f85bedeb2f
commit 7039b6a287
3 changed files with 7 additions and 9 deletions

View File

@ -569,10 +569,8 @@ class CityInfo {
// Matching uniques provided by sources in the city itself
fun getLocalMatchingUniques(placeholderText: String): Sequence<Unique> {
return (
cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText) +
religion.getMatchingUniques(placeholderText)
).asSequence()
return cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText) +
religion.getMatchingUniques(placeholderText)
}
// Get all uniques that originate from this city
@ -582,7 +580,7 @@ class CityInfo {
// Get all matching uniques that don't apply to only this city
fun getMatchingUniquesWithNonLocalEffects(placeholderText: String): Sequence<Unique> {
return cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText).asSequence()
return cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText)
.filter { it.params.none { param -> param == "in this city" } }
// Note that we don't query religion here, as those only have local effects (for now at least)
}

View File

@ -256,7 +256,7 @@ class CivilizationInfo {
} +
policies.policyUniques.getUniques(uniqueTemplate) +
tech.getTechUniques().filter { it.placeholderText == uniqueTemplate } +
temporaryUniques.filter { it.first.placeholderText == uniqueTemplate }.map { it.first }
temporaryUniques.asSequence().filter { it.first.placeholderText == uniqueTemplate }.map { it.first }
}
//region Units

View File

@ -25,10 +25,10 @@ class UniqueMap:HashMap<String, ArrayList<Unique>>() {
this[unique.placeholderText]!!.add(unique)
}
fun getUniques(placeholderText: String): List<Unique> {
fun getUniques(placeholderText: String): Sequence<Unique> {
val result = this[placeholderText]
if (result == null) return listOf()
else return result
if (result == null) return sequenceOf()
else return result.asSequence()
}
fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() }