mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-04 22:50:50 +07:00
Add cache for terrain filter results
This commit is contained in:
parent
be17bbb389
commit
7f2b98be17
@ -144,8 +144,15 @@ class Terrain : RulesetStatsObject() {
|
||||
return textList
|
||||
}
|
||||
|
||||
/** Terrain filter matching is "pure" - input always returns same output, and it's called a bajillion times */
|
||||
val cachedMatchesFilterResult = HashMap<String, Boolean>()
|
||||
|
||||
fun matchesFilter(filter: String): Boolean {
|
||||
return MultiFilter.multiFilter(filter, { matchesSingleFilter(it) })
|
||||
val cachedAnswer = cachedMatchesFilterResult[filter]
|
||||
if (cachedAnswer != null) return cachedAnswer
|
||||
val newAnswer = MultiFilter.multiFilter(filter, { matchesSingleFilter(it) })
|
||||
cachedMatchesFilterResult[filter] = newAnswer
|
||||
return newAnswer
|
||||
}
|
||||
|
||||
/** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */
|
||||
|
Loading…
Reference in New Issue
Block a user