Skip to content

Commit 9c9ae9a

Browse files
committed
Fix compilation errors in main sourceset
- provide actual for assert - provide dummy actual for AbstractMutableList.modCount, expect for JVM, where it is a protected field
1 parent 6c50490 commit 9c9ae9a

File tree

17 files changed

+122
-7
lines changed

17 files changed

+122
-7
lines changed

core/commonMain/src/implementations/immutableList/BufferIterator.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package kotlinx.collections.immutable.implementations.immutableList
1818

19-
import java.util.NoSuchElementException
20-
2119
internal class BufferIterator<out T>(
2220
private val buffer: Array<T>,
2321
index: Int,

core/commonMain/src/implementations/immutableList/PersistentVector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kotlinx.collections.immutable.implementations.immutableList
1919
import kotlinx.collections.immutable.PersistentList
2020
import kotlinx.collections.immutable.internal.ListImplementation.checkElementIndex
2121
import kotlinx.collections.immutable.internal.ListImplementation.checkPositionIndex
22+
import kotlinx.collections.immutable.internal.assert
2223

2324
/**
2425
* Persistent vector made of a trie of leaf buffers entirely filled with [MAX_BUFFER_SIZE] elements and a tail having

core/commonMain/src/implementations/immutableList/PersistentVectorBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import kotlinx.collections.immutable.PersistentList
2020
import kotlinx.collections.immutable.internal.ListImplementation.checkElementIndex
2121
import kotlinx.collections.immutable.internal.ListImplementation.checkPositionIndex
2222
import kotlinx.collections.immutable.internal.MutabilityOwnership
23+
import kotlinx.collections.immutable.internal.assert
24+
import kotlinx.collections.immutable.internal.modCount
2325

2426
class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
2527
private var vectorRoot: Array<Any?>?,

core/commonMain/src/implementations/immutableList/SmallPersistentVector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.collections.immutable.ImmutableList
2020
import kotlinx.collections.immutable.PersistentList
2121
import kotlinx.collections.immutable.internal.ListImplementation.checkElementIndex
2222
import kotlinx.collections.immutable.internal.ListImplementation.checkPositionIndex
23+
import kotlinx.collections.immutable.internal.assert
2324
import kotlinx.collections.immutable.mutate
2425

2526
internal class SmallPersistentVector<E>(private val buffer: Array<Any?>) : ImmutableList<E>, AbstractPersistentList<E>() {

core/commonMain/src/implementations/immutableMap/PersistentHashMapBuilderContentIterators.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package kotlinx.collections.immutable.implementations.immutableMap
1818

19+
import kotlinx.collections.immutable.internal.assert
20+
1921

2022
internal class TrieNodeMutableEntriesIterator<K, V>(private val builder: PersistentHashMapBuilder<K, V>)
2123
: TrieNodeBaseIterator<K, V, MutableMap.MutableEntry<K, V>>() {

core/commonMain/src/implementations/immutableMap/PersistentHashMapContentIterators.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package kotlinx.collections.immutable.implementations.immutableMap
22

3+
import kotlinx.collections.immutable.internal.assert
4+
import kotlin.js.JsName
5+
36
internal const val TRIE_MAX_HEIGHT = 7
47

58
internal abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T> {
@@ -93,6 +96,7 @@ internal open class MapEntry<out K, out V>(override val key: K, override val val
9396
internal abstract class PersistentHashMapBaseIterator<K, V, T>(node: TrieNode<K, V>,
9497
protected val path: Array<TrieNodeBaseIterator<K, V, T>>) : Iterator<T> {
9598
private var pathLastIndex = 0
99+
@JsName("_hasNext")
96100
private var hasNext = true
97101

98102
init {

core/commonMain/src/implementations/immutableMap/TrieNode.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ internal class TrieNode<K, V>(
8989
private set
9090

9191
/** Returns number of entries stored in this trie node (not counting subnodes) */
92-
internal fun entryCount(): Int = Integer.bitCount(dataMap)
92+
@UseExperimental(ExperimentalStdlibApi::class)
93+
internal fun entryCount(): Int = dataMap.countOneBits()
9394

9495
// here and later:
9596
// positionMask — an int in form 2^n, i.e. having the single bit set, whose ordinal is a logical position in buffer
@@ -106,13 +107,15 @@ internal class TrieNode<K, V>(
106107
}
107108

108109
/** Gets the index in buffer of the data entry key corresponding to the position specified by [positionMask]. */
110+
@UseExperimental(ExperimentalStdlibApi::class)
109111
internal fun entryKeyIndex(positionMask: Int): Int {
110-
return ENTRY_SIZE * Integer.bitCount(dataMap and (positionMask - 1))
112+
return ENTRY_SIZE * (dataMap and (positionMask - 1)).countOneBits()
111113
}
112114

113115
/** Gets the index in buffer of the subtrie node entry corresponding to the position specified by [positionMask]. */
116+
@UseExperimental(ExperimentalStdlibApi::class)
114117
internal fun nodeIndex(positionMask: Int): Int {
115-
return buffer.size - 1 - Integer.bitCount(nodeMap and (positionMask - 1))
118+
return buffer.size - 1 - (nodeMap and (positionMask - 1)).countOneBits()
116119
}
117120

118121
/** Retrieves the buffer element at the given [keyIndex] as key of a data entry. */

core/commonMain/src/implementations/immutableSet/PersistentHashSetIterator.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package kotlinx.collections.immutable.implementations.immutableSet
1818

19+
import kotlinx.collections.immutable.internal.assert
20+
import kotlin.js.JsName
21+
1922
internal open class PersistentHashSetIterator<E>(node: TrieNode<E>) : Iterator<E> {
2023
protected val path = mutableListOf(TrieNodeIterator<E>())
2124
protected var pathLastIndex = 0
25+
@JsName("_hasNext")
2226
private var hasNext = true
2327

2428
init {

core/commonMain/src/implementations/immutableSet/PersistentHashSetMutableIterator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package kotlinx.collections.immutable.implementations.immutableSet
1818

19+
import kotlinx.collections.immutable.internal.assert
20+
1921
internal class PersistentHashSetMutableIterator<E>(private val builder: PersistentHashSetBuilder<E>)
2022
: PersistentHashSetIterator<E>(builder.node), MutableIterator<E> {
2123
private var lastIteratedElement: E? = null
@@ -56,7 +58,8 @@ internal class PersistentHashSetMutableIterator<E>(private val builder: Persiste
5658
}
5759

5860
val position = 1 shl ((hashCode shr (pathIndex * LOG_MAX_BRANCHING_FACTOR)) and MAX_BRANCHING_FACTOR_MINUS_ONE)
59-
val index = Integer.bitCount(node.bitmap and (position - 1))
61+
@UseExperimental(ExperimentalStdlibApi::class)
62+
val index = (node.bitmap and (position - 1)).countOneBits()
6063

6164
path[pathIndex].reset(node.buffer, index)
6265

core/commonMain/src/implementations/immutableSet/TrieNode.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ internal class TrieNode<E>(
6464
return bitmap and positionMask == 0
6565
}
6666

67+
@UseExperimental(ExperimentalStdlibApi::class)
6768
private fun indexOfCellAt(positionMask: Int): Int {
68-
return Integer.bitCount(bitmap and (positionMask - 1))
69+
return (bitmap and (positionMask - 1)).countOneBits()
6970
}
7071

7172
private fun elementAtIndex(index: Int): E {

0 commit comments

Comments
 (0)