Skip to content

Commit

Permalink
perf(cpu): Sequences, and initially set array list to desired size
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Dec 9, 2024
1 parent 1c25206 commit bdc5cd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bdc5cd2

Please sign in to comment.