diff --git a/kds/src/commonMain/kotlin/korlibs/datastructure/FastSmallSet.kt b/kds/src/commonMain/kotlin/korlibs/datastructure/FastSmallSet.kt index aac539ee6b..03b9d6b4e0 100644 --- a/kds/src/commonMain/kotlin/korlibs/datastructure/FastSmallSet.kt +++ b/kds/src/commonMain/kotlin/korlibs/datastructure/FastSmallSet.kt @@ -1,8 +1,10 @@ package korlibs.datastructure class FastSmallSet : AbstractMutableSet() { - @PublishedApi internal val _items = FastArrayList() - val items: List get() = _items + @PublishedApi internal val _items = LinkedHashSet() + //@PublishedApi internal val _items = FastArrayList() + //val itemsToIndex = LinkedHashMap() + //val items: List get() = _items override val size: Int get() = _items.size override fun iterator(): MutableIterator = _items.iterator() @@ -13,6 +15,7 @@ class FastSmallSet : AbstractMutableSet() { override fun add(element: T): Boolean { if (element in this) return false + //itemsToIndex[element] = _items.size _items.add(element) return true } @@ -21,12 +24,16 @@ class FastSmallSet : AbstractMutableSet() { fast0 = null fast1 = null fast2 = null - return _items.remove(element) + //val index = itemsToIndex.remove(element) ?: return false + //_items.removeAt(index) + _items.remove(element) + return true } override operator fun contains(element: T): Boolean { if (element === fast0 || element === fast1 || element === fast0) return true val result = element in _items + //val result = element in itemsToIndex if (result) { fast1 = fast0 fast2 = fast1 @@ -36,6 +43,7 @@ class FastSmallSet : AbstractMutableSet() { } override fun clear() { + //itemsToIndex.clear() _items.clear() fast0 = null fast1 = null @@ -43,6 +51,7 @@ class FastSmallSet : AbstractMutableSet() { } inline fun fastForEach(block: (T) -> Unit) { - _items.fastForEach(block) + _items.forEach { block(it) } + //_items.fastForEach(block) } } diff --git a/korge/src/commonMain/kotlin/korlibs/korge/render/AgBufferManager.kt b/korge/src/commonMain/kotlin/korlibs/korge/render/AgBufferManager.kt index c0587fd0b4..3a7dff72d2 100644 --- a/korge/src/commonMain/kotlin/korlibs/korge/render/AgBufferManager.kt +++ b/korge/src/commonMain/kotlin/korlibs/korge/render/AgBufferManager.kt @@ -39,7 +39,7 @@ class AgBufferManager( } fun gc() { - delete(referencedBuffersSinceGC.items) + referencedBuffersSinceGC.fastForEach { delete(it) } referencedBuffersSinceGC.clear() }