perf(cpu): Sequences, and initially set array list to desired size

This commit is contained in:
yairm210 2024-12-09 18:44:17 +02:00
parent 1c25206dbb
commit bdc5cd2ecf
3 changed files with 6 additions and 6 deletions

View File

@ -262,7 +262,7 @@ object NextTurnAutomation {
}
val stateForConditionals = civInfo.state
while(civInfo.tech.freeTechs > 0) {
while (civInfo.tech.freeTechs > 0) {
val costs = getGroupedResearchableTechs()
if (costs.isEmpty()) return

View File

@ -102,11 +102,11 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
.flatMap { getMatchingEdges(tile, it) }
}
private fun getMatchingEdges(originTile: Tile, neighborTile: Tile): List<String>{
private fun getMatchingEdges(originTile: Tile, neighborTile: Tile): Sequence<String>{
val vectorToNeighbor = neighborTile.position.cpy().sub(originTile.position)
val direction = NeighborDirection.fromVector(vectorToNeighbor)
?: return emptyList()
val possibleEdgeFiles = strings().edgeImagesByPosition[direction] ?: return emptyList()
?: return emptySequence()
val possibleEdgeFiles = strings().edgeImagesByPosition[direction] ?: return emptySequence()
// Required for performance - full matchesFilter is too expensive for something that needs to run every update()
fun matchesFilterMinimal(originTile: Tile, filter: String): Boolean {
@ -115,7 +115,7 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
return false
}
return possibleEdgeFiles.filter {
return possibleEdgeFiles.asSequence().filter {
if (!matchesFilterMinimal(originTile, it.originTileFilter)) return@filter false
if (!matchesFilterMinimal(neighborTile, it.destinationTileFilter)) return@filter false
return@filter true

View File

@ -33,7 +33,7 @@ class EditorMapHolder(
val tileGroups = HashMap<Tile, TileGroup>()
private lateinit var tileGroupMap: TileGroupMap<TileGroup>
private val allTileGroups = ArrayList<TileGroup>()
private val allTileGroups = ArrayList<TileGroup>(tileMap.values.size)
private var blinkAction: Action? = null