Skip to content

Commit

Permalink
Make loading a large number of regions more optimal
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Apr 7, 2024
1 parent aa47e37 commit 916623f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/persistence.nim
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ proc readLevelRegions(rr; regionCols: Natural,
var regions: Regions = initRegions()

for regionIdx in 0..<numRegions:
debug(fmt"index: {regionIdx}")
debug(fmt"regionIdx: {regionIdx}")
pushDebugIndent()

let regionCoords = if version < 4:
Expand All @@ -782,10 +782,13 @@ proc readLevelRegions(rr; regionCols: Natural,
let notes = rr.readWStr
checkStringLength(notes, "lvl.regn.region.notes", NotesLimits)

regions[regionCoords] = initRegion(name=name, notes=notes)
# Optimisation: sorting only once at the end speeds up the loading
# massively
regions.regionsByCoords[regionCoords] = initRegion(name=name, notes=notes)

popDebugIndent()

regions.sortRegions
result = (regionOpts, regions)

popDebugIndent()
Expand Down

0 comments on commit 916623f

Please sign in to comment.