Bring back fastutil usage

This commit is contained in:
DBotThePony 2024-02-03 18:04:01 +07:00
parent 4407fc3de6
commit 36b2f0670c
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -2,6 +2,9 @@
package ru.dbotthepony.kommons.networking
import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.ReferenceArraySet
import ru.dbotthepony.kommons.collect.ProxiedMap
import ru.dbotthepony.kommons.collect.forValidRefs
import ru.dbotthepony.kommons.event.IBooleanSubscriptable
@ -320,11 +323,11 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
}
}
private val dirtyFields = LinkedHashSet<AbstractField<*>>()
private val dirtyFields = ReferenceArraySet<AbstractField<*>>(4)
// use LinkedList because it is ensured memory is freed on LinkedList#clear
private val mapBacklogs = IdentityHashMap<Map<*, *>, LinkedList<Pair<Any?, (DataOutputStream) -> Unit>>>()
private val setBacklogs = IdentityHashMap<Set<*>, LinkedList<Pair<Any?, (DataOutputStream) -> Unit>>>()
private val mapBacklogs = Reference2ObjectOpenHashMap<Map<*, *>, LinkedList<Pair<Any?, (DataOutputStream) -> Unit>>>()
private val setBacklogs = Reference2ObjectOpenHashMap<Set<*>, LinkedList<Pair<Any?, (DataOutputStream) -> Unit>>>()
var unused: Boolean = false
private set
@ -372,9 +375,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
return LinkedList()
}
return mapBacklogs.computeIfAbsent(map) {
return mapBacklogs.computeIfAbsent(map, Reference2ObjectFunction {
LinkedList()
}
})
}
internal fun <K, V> removeMapBacklog(map: Map<K, V>) {
@ -386,9 +389,9 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
return LinkedList()
}
return setBacklogs.computeIfAbsent(set) {
return setBacklogs.computeIfAbsent(set, Reference2ObjectFunction {
LinkedList()
}
})
}
internal fun <V> removeSetBacklog(set: Set<V>) {