Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/com/mapconductor/compose/AddProgress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ internal class AddProgressTracker(
var onAddProgress: ((added: Int, total: Int) -> Unit)? = null
var onAddEnd: ((total: Int) -> Unit)? = null

/** State objects handed over and not on the map yet, by id. */
/**
* State objects handed over and not on the map yet, by id.
*
* Replaced, not just emptied, once the last one arrives: a HashMap keeps
* its table at the largest size it reached, and for 720k circles that was
* an empty 8 MB array held for as long as the collection was shown.
*/
private var pending = HashMap<String, ComponentState>()
private var total = 0
private var added = 0
Expand Down Expand Up @@ -85,7 +91,11 @@ internal class AddProgressTracker(
if (newStates.isEmpty()) return
timer?.cancel()
timer = null
pending = HashMap<String, ComponentState>(newStates.size * 2).apply { for (s in newStates) put(s.id, s) }
// Room for every state without a resize at the 0.75 load factor, and no more.
pending =
HashMap<String, ComponentState>((newStates.size / 0.75f).toInt() + 1).apply {
for (s in newStates) put(s.id, s)
}
total = newStates.size
added = 0
lastProgressAt = Long.MIN_VALUE / 2
Expand Down Expand Up @@ -115,6 +125,7 @@ internal class AddProgressTracker(

private fun finishIfDone() {
if (pending.isNotEmpty()) return
pending = HashMap()
timer?.cancel()
timer = null
onAddProgress?.invoke(total, total)
Expand Down
Loading